B1038 统计同成绩学生 (20分)

2020-01-29  本文已影响0人  km15

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

/*
考察:hashtable + 应用:相同成绩统计

编程思想:
1、一个hashtable,初始为0,
2、遍历这n个数,hashtable[i]++
3、输入这N个查询的数,输入hashtable[i]的值

learn && wrong;
1、hashtable不用开太大的!
*/

include <iostream>

using namespace std;
int hashtable[110] = { 0 };

int main(int argc, char** argv) {
int n;
cin>>n;
int score;

for(int i = 0;i < n;++i){  //输入数字,并累计hashtable 
    cin>>score;  
    ++hashtable[score];
}

int m; //查询的人数 
int temp; //查询的下标数 
cin>>m;
for(int i = 0;i < m;++i){
    cin>>temp;
    if(i != (m - 1))
    cout<<hashtable[temp]<<" ";
    else cout<<hashtable[temp];
}   
return 0;

}

上一篇 下一篇

猜你喜欢

热点阅读