Source Code:
#include<stdio.h>
int main(void) {
short unsigned bucket[101] = { 0 }; // -50 to 50
short unsigned n; // 0 to 1000
short a; // -50 to 50
scanf("%hu", &n);
for (short unsigned i = 1; i <= n; ++i) {
scanf("%hd", &a);
++bucket[a + 50]; // -50 -> 0
}
for (short unsigned i = 0; i < 101; ++i) {
if (bucket[i] > n / 2)
printf("%hd\n", i - 50);
}
return 0;
}
这篇文章展示了如何使用C语言编写一个程序,该程序接收用户输入的整数,将它们映射到一个数组中,并根据数组元素的值确定并输出数组中值大于一半的元素(即中值)。
1208

被折叠的 条评论
为什么被折叠?



