map-hdu 4287-Intelligent IME-想法题

题意:对应老式手机上的9格按键 每个按键对应了几个字母,现在告诉你输入几个数字和几个字符串让你求与字符串匹配的数字有多少个

思路 :每读入一个字符串把他对应的数字求出,以 a+b*10+c*100表示 这样对应的每个按特定组合按下的键 得到的字符窜都只有一个数字且唯一,然后看对应的数字有没有对应的字符串以及有多少个(ps:求关注)

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int num[2000000];
int a[10000];
char str[20];
int cc(char str[])
{
    int len=strlen(str);
    int ans=0;
    for(int i=0;i<len;i++){
        ans*=10;
        if(str[i]>='a' && str[i]<='c')
            ans+=2;
        else if(str[i]>='d'&& str[i]<='f')
            ans+=3;
        else if(str[i]>='g'&&str[i]<='i')
            ans+=4;
        else if(str[i]>='j' && str[i]<='l')
            ans+=5;
        else if(str[i]>='m'&&str[i]<='o')
            ans+=6;
        else if(str[i]>='p'&&str[i]<='s')
            ans+=7;
        else if(str[i]>='t'&&str[i]<='v')
            ans+=8;
        else ans+=;
    }
    return ans;
}
int main()
{
    int T;
    int n,m,x;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        for(int i=0;i<m;i++){
            scanf("%s",&str);
            x=cc(str);
            num[x]++;
        }
        for(int i=0;i<n;i++)
          printf("%d\n",num[a[i]]);
    }
    return 0;
}


posted @ 2014-09-27 23:02  Scale_the_heights  阅读(139)  评论(0编辑  收藏  举报