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("
");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/visper/p/10100021.html