TimesIsMoney
Description
给你一个序列,有N个整数(int以内),判断一个数在这个序列中出现几次。
Input
多组输入,输入到文件结尾
首先输入一个n,然后输入n个整数。
在输入一个m,代表查询的个数 ,然后输入m个数(int以内)。
n,m <= 100000;
Output
对应每一次查询,输出这个数在序列中出现几次。
Samples
Sample #1
Input
5
1 2 2 3 5
3
2 4 5
Output
2
0
1
分析:
TLE麻了,map好用!
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
while(cin >> n) {
int a;
map<int, long long int>Map;
while(n --){
// memset(a, 0, sizeof(a));
scanf("%d",&a);
Map[a] ++;
}
cin >> m;
int b;
while(m --){
// memset(b, 0, sizeof(b));
scanf("%d",&b);
printf("%d\n", Map[b]);
}
}
return 0;
}