2017级算法第二次上机-E.SkyLee的图书整理

这道题考察了map函数的使用,map最简单的理解就是把一个数映射到一个数。然后使用map也类似hash数组的方法即可 

map的头文件是<map> map<int,int> 将一个数映射到一个数

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
int main(){
    
    int n,t,x,i,j,k;
    while(~scanf("%d %d",&n,&t)){
        map<int,int> count;
        for(i=0;i<n;i++){
            scanf("%d",&x);
            count[x]++;
        }
        for(i=0;i<t;i++){
            scanf("%d",&x);
            printf("%d ",count[x]);
        }
        printf("\n");
    }
    return 0;
}

 

posted on 2018-12-10 23:45  Visper  阅读(205)  评论(0编辑  收藏  举报