直接map就水过去了。。
1 #include <map> 2 #include <string> 3 #include <stdio.h> 4 #include <iostream> 5 using namespace std; 6 map<string,int> mp; 7 string s[5005],s1; 8 int cas,n,m,cc[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; 9 main(){ 10 for(cin>>cas;cas--;){ 11 cin>>n>>m;mp.clear(); 12 for(int i=1;i<=n;i++)cin>>s[i]; 13 while(m--){ 14 cin>>s1; 15 for(int i=1;i<=s1.length();i++)s1[i-1]=cc[s1[i-1]-'a']+'0'; 16 mp[s1]++; 17 } 18 for(int i=1;i<=n;i++)printf("%d\n",mp[s[i]]); 19 } 20 }