1038. 统计同成绩学生(20)

原题: https://www.patest.cn/contests/pat-b-practise/1038

思路: 分数当成数组下标用, so easy!

实现:

#include <stdio.h>

int main (void) {
    int n; // 学生总数
    int s; // 要查询的学生数
    int score[101] = {0};
    int temp;
    int i;
    char ch = ' ';

    scanf("%d", &n);
    for (i=1; i<=n; i++) {
        scanf("%d", &temp);
        score[temp]++;
    }
    scanf("%d", &s);
    for (i=1; i<=s; i++) {
        scanf("%d", &temp);
        if (i == s) ch = '\n';
        printf("%d%c", score[temp], ch);
    }

    return 0;
}
posted @ 2017-11-12 22:04  阿胜4K  阅读(313)  评论(0编辑  收藏  举报