傳送門
https://pintia.cn/problem-sets/994805260223102976/problems/994805284092887040
題目
本題要求讀入N名學(xué)生的成績,將獲得某一給定分數(shù)的學(xué)生人數(shù)輸出。
輸入格式:
輸入在第1行給出不超過10^5
的正整數(shù)N,即學(xué)生總?cè)藬?shù)。隨后1行給出N名學(xué)生的百分制整數(shù)成績,中間以空格分隔。最后1行給出要查詢的分數(shù)個數(shù)K(不超過N的正整數(shù)),隨后是K個分數(shù),中間以空格分隔。
輸出格式:
在一行中按查詢順序給出得分等于指定分數(shù)的學(xué)生人數(shù),中間以空格分隔,但行末不得有多余空格。
輸入樣例:
10
60 75 90 55 75 99 82 90 75 50
3 75 90 88
輸出樣例:
3 2 0
分析
先新建成績表,用于統(tǒng)計同成績的人數(shù),讀入每個成績,根據(jù)每個成績,將對應(yīng)索引的成績表的數(shù)值自增1,最后按照所求成績,輸出人數(shù)即可。
源代碼
//C/C++實現(xiàn)
#include <iostream>
using namespace std;
int grade[101];
int main(){
int n;
scanf("%d", &n);
int tmp;
for(int i = 0; i < n; ++i){
scanf("%d", &tmp);
++grade[tmp];
}
int k;
scanf("%d", &k);
scanf("%d", &tmp);
printf("%d", grade[tmp]);
for(int i = 1; i < k; ++i){
scanf("%d", &tmp);
printf(" %d", grade[tmp]);
}
printf("\n");
return 0;
}