A solution in c++
#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long int ll;
//Int data type
#define sc1(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define sc3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sc4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
//Long Data type
#define scl1(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scl4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define mx 100005
#define pf(a) cout<<a<<endl
int main()
{
ll n,m,i,j=0,k=0,t,a=0,b,ck=0,dk=0;
map<string, ll>my;
map<string, ll>::iterator it;
scl1(n);
string arr,brr;
for(i=0; i<n; i++){
cin>>arr;
my[arr]++;
}
scl1(m);
a=0;
for(i=0; i<m; i++){
cin>>arr;
a=0;
for(it = my.begin(); it!=my.end(); it++){
brr = it->first;
if(arr.compare(brr)==0){
cout<<it->second<<endl;
brr.clear();
a = 1;
break;
}
}
if(a==0)
cout<<"0"<<endl;
}
}


0 Comments
If you have any doubts, Please let me know