2 : a, b, c 3 : d, e, f 4 : g, h, i 5 : j, k, l 6 : m, n, o
7 : p, q, r, s 8 : t, u, v 9 : w, x, y, z
When we want to input the word “wing”, we press the button 9, 4, 6, 4, then the input method will choose from an embedded dictionary, all words matching the input number sequence, such as “wing”, “whoi”, “zhog”. Here comes our question, given a dictionary, how many words in it match some input number sequences?
Two integer N (1 <= N <= 5000), M (1 <= M <= 5000), indicating the number of input number sequences and the number of words in the dictionary, respectively. Then comes N lines, each line contains a number sequence, consisting of no more than 6 digits. Then comes M lines, each line contains a letter string, consisting of no more than 6 lower letters. It is guaranteed that there are neither duplicated number sequences nor duplicated words.
1 3 5 46 64448 74 go in night might gn
3 2 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
string letter="22233344455566677778889999";
int n,m,t;
map<string,int>a;
vector<string>name;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
string z;
cin>>z;
name.push_back(z);
}
for(int i=0;i<m;i++)
{
string z;
cin>>z;
for(int j=0;z[j]!='\0';j++)
z[j]=letter[z[j]-'a'];
a[z]++;
}
for(int i=0;i<n;i++)
cout<<a[name[i]]<<endl;
a.clear();
name.clear();
}
return 0;
}
4638



被折叠的 条评论
为什么被折叠?



