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;
}


转载于:https://www.cnblogs.com/Scale-the-heights/p/4322374.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值