VotMajoritar 

#include // avem maxim un milion de numere... // using namespace std; ifstream f ("vot.in"); ofstream g ("vot.out"); long n,x,votm,vot,nrvoturi; // votm/ vot majoritar posibil // nrvoturi pentru votm //vot- numarul curent citit int main { f>>n; long i,contor=0; //presupun ca primul e majoritar f>>votm; contor=1; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> for( i=2;i<=n;++i) <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> { f>>vot; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> if(votm==vot) ++ contor; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> else <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> { --contor; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> if(contor<0) {votm=vot;contor=1;} <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> } <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> } <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> // inchid fisierul ca sa pot sa-l redeschid si sa mai citesc o data numerele <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">f.close; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">// redeschid fisierul pentru citire <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">ifstream f ("vot.in"); <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">//verific daca e majoritar votm <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">f>>n; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">// trebuie sa-l recitesc pe n daca e specificat in enunt ca e primul in fisier <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">for (i=1;i<=n;++i) <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">{ f>> vot; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> if(vot==votm) ++nrvoturi; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">} <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">// atentie enunt... ce inseamna majoritar <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">if(nrvoturi>=n/2+1) g<<votm; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> else g<<-1; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">f.close; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">g.close; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;"> return 0; <span style="font-family: 'Times New Roman',serif; font-size: 12pt;">}
 * __ Sol.Carmen __**