题解 | #记票统计#
记票统计
http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
20行的代码为什么要写五六十行
#include<stdio.h>
#include<string.h>
int main() {
int n, m;
char name[101][32];
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++)
scanf("%s", name[i]);
sscanf("Invalid","%s",name[n]);//初始化n+1
scanf("%d", &m);
int sum[101];//统计票数
for (int i = 0; i < 101; i++)sum[i] = 0;
for (int i = 0; i < m; i++) {
char vote[32];
scanf("%s", vote);
int j;
for (j = 0; j < n; j++)
if (strcmp(vote, name[j]) == 0)break;
sum[j]++;
}
for (int i = 0; i <= n; i++)printf("%s : %d\n", name[i], sum[i]);
}
}