题解 | #记票统计#

记票统计

https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894

#include <stdio.h>
#include <string.h>
typedef struct people {
    char name[100];
    int num;
} people;
int main() {
    int n;
    scanf("%d ", &n);
    people p[101];
    for (int i = 0; i < n; i++) {
        scanf("%s", p[i].name);
        p[i].num = 0;
    }
    int m;
    char xn[101];
    int count = 0;
    scanf("%d ", &m);
    for (int j = 0; j < m; j++) {
        scanf("%s", xn);
        for (int i = 0; i < n; i++) {
            if (strcmp(p[i].name, xn) == 0) {
                p[i].num++;
                count++;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        printf("%s : %d\n", p[i].name, p[i].num);
    }
    printf("Invalid : %d\n", m - count);
    return 0;
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务