kaka12346 2015-09-20 07:42 采纳率: 0%
浏览 1558

菜鸟求解:Intelligent IME无法AC,求帮忙

题目:
Problem Description
  We all use cell phone today. And we must be familiar with the intelligent English input method on the cell phone. To be specific, the number buttons may correspond to some English letters respectively, as shown below:
  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?

Input
  First is an integer T, indicating the number of test cases. Then T block follows, each of which is formatted like this:
  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.

Output
  For each input block, output N integers, indicating how many words in the dictionary match the corresponding number sequence, each integer per line.

Sample Input
1
3 5
46
64448
74
go
in
night
might
gn

Sample Output
3
2
0

代码:
#include
#include
#include
#define N 5010
using namespace std;
class II
{
private:
int sn,sw,num[N],si[N],count[N];
mapword;
public:
void initial()
{
sn=0;
sw=0;
word['a']=2,word['b']=2,word['c']=2,word['d']=3,word['e']=3,word['f']=3,word['g']=4,word['h']=4,word['i']=4,word['j']=5;
word['k']=5,word['l']=5,word['m']=6,word['n']=6,word['o']=6,word['p']=7,word['q']=7,word['r']=7,word['s']=7,word['t']=8;
word['u']=8,word['v']=8,word['w']=9,word['x']=9,word['y']=9,word['z']=9;
}
void read()
{
int i,j,s=0;
cin>>sn>>sw;
for(i=0; i {
cin>>num[i];
count[i]=0;
}
for(i=0; i<=sw; i++)
{
char c;
while(cin.get(c))
{
if(c=='\n')
break;
while(c!=' ' && c!='\n')
{
s=s*10+word[c];
cin.get(c);
}
for(j=0; j {
if(s==num[j])
count[j]++;
}
s=0;
break;
}
}
}
void out()
{
int i;
for(i=0; i {
cout }
}
};
int main()
{
int n;
while(cin>>n)
{
II myii;
myii.initial();
myii.read();
myii.out();
}
return 0;
}

  • 写回答

1条回答 默认 最新

  • devmiao 2015-09-20 15:22
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值