Cod sursa(job #2626743)
Utilizator | Data | 7 iunie 2020 21:09:36 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include<fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main()
{
int n,nCopy;
int i=1,j,x;
int elMaj,cntAppearance=0;
fin>>n;
while(i<=n/2+1)
{
for(j=1;j<=i;j++)
fin>>elMaj;
ifstream fin("elmaj.in");
fin>>nCopy;
for(j=1;j<=nCopy;j++)
{
fin>>x;
if(x==elMaj)
cntAppearance++;
}
if(cntAppearance>=n/2+1)
{
fout<<elMaj<<" "<<cntAppearance;
return 0;
}
i++;
}
return 0;
}