题目描述:https://pycoder.blog.csdn.net/article/details/124741287
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int myCmp(const void *a, const void *b)
{
int *aa = (int *)a;
int *bb = (int *)b;
return *aa - *bb;
}
int main() {
char str[10000] = {0};
int index = 0;
int arr[1000] = {0};
int hash[1000] = {0};
int new_index = 0;
int new[1000] = {0};
int max = 0;
gets(str);
char* tmp = strtok(str, " ");
arr[index++] = atoi(tmp);
hash[atoi(tmp)]++;
max = hash[atoi(tmp)];
while (1) {
tmp = strtok(NULL, " ");
if (tmp == NULL) break;
arr[index++] = atoi(tmp);
hash[atoi(tmp)]++;
if (hash[atoi(tmp)] > max) {
max = hash[atoi(tmp)];
}
}
for (int i = 0; i < index; i++) {
printf("%d %d %d %d\n", i, arr[i], hash[arr[i]], max);
if (hash[arr[i]] == max) {
new[new_index++] = arr[i];
}
}
qsort(new, new_index, sizeof(new[0]), myCmp);
if (new_index % 2 == 0) {
printf("%0.1f\n", ((float)new[new_index/2] + new[new_index/2 - 1]) / 2);
} else {
printf("%d\n", new[new_index/2]);
}
return 0;
}