Pagini recente » Cod sursa (job #2182454) | Cod sursa (job #1875988) | Cod sursa (job #822149) | Cod sursa (job #1016573) | Cod sursa (job #3245900)
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
FILE *fin, *fout;
fin = fopen("elmaj.in", "r");
fout = fopen("elmaj.out", "w");
int n, cnt, maj, x;
cnt = 1;
fscanf(fin, "%d %d", &n, &maj);
vector<int> v(n);
v[0] = maj;
for (int i = 1; i < n; i++) {
fscanf(fin, "%d", &x);
v[i] = x;
if (maj == x) {
cnt++;
continue;
}
cnt--;
if (cnt == 0) {
maj = x;
cnt = 1;
}
}
cnt = 0;
for (int i = 0; i < n; i++)
cnt += (maj == v[i]);
fprintf(fout, "%d %d\n", maj, cnt);
fclose(fin);
fclose(fout);
return 0;
}