题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
#include <stdio.h> #include <string.h> int main() { int n; char names[100][32] = {0}; int count[100] = {0}; int v; char voits[100][32] = {0}; //get names scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%s",names[i]); } //get voits scanf("%d",&v); for(int i = 0; i < v; i++) { scanf("%s",voits[i]); } //count int findFLag = 0; int otherName = 0; for(int i = 0; i < v; i++) { findFLag = 0; for(int j = 0; j < n; j++) { if(0 == strcmp(voits[i],names[j])) { findFLag = 1; count[j]++; break; } } if(0 == findFLag) otherName++; } for(int i = 0; i < n; i++) { printf("%s : %d\n",names[i],count[i]); } printf("Invalid : %d",otherName); return 0; }