题解 | #统计同成绩学生人数#练习下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"); } } }