题解 | #统计同成绩学生人数#练习下map

统计同成绩学生人数

https://www.nowcoder.com/practice/987123efea5f43709f31ad79a318ca69

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    map<int, int> score;
    while (scanf("%d", &n) != EOF) {
        if (0 == n) {
            break;
        }
        for (int i = 0; i < n; i++) {
            int t;
            scanf("%d", &t);
            if (score.find(t) != score.end()) { //有这个成绩
                score[t]++;
            } else {
                score[t] = 1;
            }
        }
        int t;
        scanf("%d", &t);
        if (score.find(t) != score.end()) { //有这个成绩
            printf("%d\n", score[t]);
        } else {
            printf("0\n");
        }
    }
}

全部评论

相关推荐

11-03 13:18
门头沟学院 Java
包行:平时怎么刷算法题的哇,字节的手撕听说都很难
字节跳动工作体验
点赞 评论 收藏
分享
苗条的伊泽瑞尔最喜欢...:同28届被压力了,电科✌就不能去卷算法吗?把Java留给我们双非卷
投递快手等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务