HDU 4287 Intelligent IME 地图的应用
HDU 4287 Intelligent IME map的应用
来源:http://acm.hdu.edu.cn/showproblem.php?pid=4287
题意:首先给你一些由数字组成的串,数字分别对应于手机键盘上的一些字母。然后给一些字符串,问每个字符串能对应几个上面出现过的数字串。
思路:用map可以解决。网络赛最简单的题了。
来源:http://acm.hdu.edu.cn/showproblem.php?pid=4287
题意:首先给你一些由数字组成的串,数字分别对应于手机键盘上的一些字母。然后给一些字符串,问每个字符串能对应几个上面出现过的数字串。
思路:用map可以解决。网络赛最简单的题了。
代码:
#include <iostream> #include <cstdio> #include <string> #include <string.h> #include <map> using namespace std; const int N = 5010; char fun(char ch){ if(ch >= 'a' && ch <= 'c') return 2; else if(ch >= 'd' && ch <= 'f') return 3; else if(ch >= 'g' && ch <= 'i') return 4; else if(ch >= 'j' && ch <= 'l') return 5; else if(ch >= 'm' && ch <= 'o') return 6; else if(ch >= 'p' && ch <= 's') return 7; else if(ch >= 't' && ch <= 'v') return 8; else return 9; } int main(){ int numcase; scanf("%d",&numcase); while(numcase--){ int n,m; scanf("%d%d",&n,&m); string ss[N]; for(int i = 0; i < n; ++i) cin >> ss[i]; string idss; map<string,int> mp; while(m--){ cin >> idss; string newss; for(int i = 0; i < idss.size(); ++i){ newss += char(fun(idss[i]) + '0'); } mp[newss]++; } for(int i = 0; i < n; ++i) printf("%d\n",mp[ss[i]]); } return 0; }