前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDU-4287 Intelligent IME

HDU-4287 Intelligent IME

作者头像
天道Vax的时间宝藏
发布2021-08-11 10:46:15
2600
发布2021-08-11 10:46:15
举报
文章被收录于专栏:用户5305560的专栏

题目:Intelligent IME

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

代码语言:javascript
复制
1
3 5
46
64448
74
go
in
night
might
gn

Sample Output

代码语言:javascript
复制
3
2
0

题解:按照手机九键拼音的方式分别输出数字组成的字符串分别有几个。

代码如下:

代码语言:javascript
复制
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<fstream>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<set>
#include<iomanip>
#include<vector>
using namespace std;
int num[5005];
char ss[5005][8];
int num1[5005];
int sum[5005]={0};
int main()
{
	int k;cin>>k;
	while(k--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			cin>>num[i];
		}
		for(int j=1;j<=m;j++)
		{
			scanf("%s",ss[j]);
		}
		/*for(int i=1;i<=n;i++)
		{
			cout<<num[i]<<"  ";
		}
		for(int j=1;j<=m;j++)
		{
			cout<<ss[j]<<"  ";
		}*/
		int t=0;
		char ssi[8];
		for(int j=1;j<=m;j++)
		{
			t=0;
			memset(ssi,'\0',sizeof(ssi));
			int lens=strlen(ss[j]);
			for(int k=0;k<lens;k++)
			{
				switch(ss[j][k]){
					case 'a':
					case 'b':
					case 'c': ssi[t++]='2';break;
					case 'd':
					case 'e':
					case 'f':ssi[t++]='3';break;
					case 'g':
					case 'h':
					case 'i':ssi[t++]='4';break;
					case 'j':
					case 'k':
					case 'l':ssi[t++]='5';break;
					case 'm':
					case 'n':
					case 'o':ssi[t++]='6';break;
					case 'p':
					case 'q':
					case 'r':
					case 's':ssi[t++]='7';break;
					case 't':
					case 'u':
					case 'v':ssi[t++]='8';break;
					case 'w':
					case 'x':
					case 'y':
					case 'z':ssi[t++]='9';break;
					
				}
			}
			//cout<<ssi<<endl;
			num1[j]=atoi(ssi);
			//cout<<num1[j]<<endl;
			//cout<<endl<<endl;
		}
		for(int j=1;j<=m;j++)
		{
			for(int i=1;i<=n;i++)
			{
				if(num1[j]==num[i])
				{
					sum[i]++;
					break;
				} 
			}
		}
		for(int i=1;i<=n;i++)
		{
			cout<<sum[i]<<endl;
		}	
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目:Intelligent IME
    • Problem Description
      • Input
        • Output
          • Sample Input
            • Sample Output
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档