code4sk/c/sourcecode/朱森森带领的奇妙冒险/2022-2023第二学期单开班第2次月考/调查电视节目受欢迎程度.cpp
2023-12-15 22:38:26 +08:00

55 lines
No EOL
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
7-6 调查电视节目受欢迎程度
分数 10
作者 颜晖
单位 浙大城市学院
某电视台要调查观众对该台8个栏目设相应栏目编号为1~8的受欢迎情况共调查了n位观众1≤n≤1000现要求编写程序输入每一位观众的投票情况每位观众只能选择一个最喜欢的栏目投票统计输出各栏目的得票情况。
输入格式:
输入在第1行中给出一个正整数n1≤n≤1000第2行输入n个整数其间以空格分隔。
输出格式:
按顺序输出所有8个栏目的编号和得票数每个数占4位每行输出一个栏目的编号和得票数。
输入样例:
10
3 4 7 6 3 9 2 3 1 8
输出样例:
1 1
2 1
3 3
4 1
5 0
6 1
7 1
8 1
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
*/
#include <stdio.h>
#include <math.h>
int main()
{
int n;
scanf("%d", &n);
int a[n], b[9], c;
for (int i = 0; i < 9; i++)
b[i] = 0;
for (int i = 0; i < n; i++)
{
int num;
scanf("%d", &num);
if (num >= 1 && num <= 8)
b[num]++;
}
for (int i = 1; i < 9; i++)
{
printf("%4d%4d\n", i, b[i]);
}
return 0;
}