Pagini recente » Cod sursa (job #1647603) | Cod sursa (job #1228457) | Cod sursa (job #629441) | Cod sursa (job #479881) | Cod sursa (job #3259303)
#include <stdio.h>
int main() {
FILE *input = fopen("elmaj.in", "r");
FILE *output = fopen("elmaj.out", "w");
int t;
fscanf(input, "%d", &t);
int arr[t];
for(int i = 0; i < t; i++) {
fscanf(input, "%d ", &arr[i]);
}
for(int i = 0; i < t; i++) {
int element = arr[i];
int count = 1;
for(int i = 1; i < t; i++) {
if(element == arr[i]) {
count++;
}
}
if(count >= t/2+1) {
fprintf(output, "%d %d", element, count);
fclose(input);
fclose(output);
return 0;
}
}
fprintf(output, "-1");
fclose(input);
fclose(output);
}