(code jam)Problem C. T9 Spelling

本文详细介绍了如何使用手机输入法将字母映射到按键组合,并解释了如何通过按键和空格符号来输入文本。重点在于理解同一按键两次输入之间的停顿表示,以及特殊字符的输入方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem

The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. We would like to make it easier to write a message to your friend using a sequence of keypresses to indicate the desired characters. The letters are mapped onto the digits as shown below. To insert the character B for instance, the program would press22. In order to insert two characters in sequence from the same key, the user must pause before pressing the key a second time. The space character ' ' should be printed to indicate a pause. For example, 2 2 indicates AA whereas 22 indicates B.

Input

The first line of input gives the number of cases, NN test cases follow. Each case is a line of text formatted as

desired_message

Each message will consist of only lowercase characters a-z and space characters ' '. Pressing zero emits a space.

Output

For each test case, output one line containing "Case #x: " followed by the message translated into the sequence of keypresses.

Limits

1 ≤ N ≤ 100.

Small dataset

1 ≤ length of message in characters ≤ 15.

Large dataset

1 ≤ length of message in characters ≤ 1000.

Sample


Input 

Output 
4
hi
yes
foo  bar
hello world

Case #1: 44 444
Case #2: 999337777
Case #3: 333666 6660 022 2777
Case #4: 4433555 555666096667775553

题意就是如题,应该不看都能看懂,就是平常手机输入法,注意空格用0输出,相同数字就用空格输出。

结果大数据纠结在上一次输入的也要记录!也就是说上一次输入比如是yes 后一次输入sk。那个s也继承上一次输入的s,要输出一个空格!!!坑啊。。。

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int main()
{
	int t,i,j;
	char s[10100];
	freopen("C-large-practice.in","r",stdin);
	freopen("output.out","w",stdout);
	scanf("%d",&t);
	getchar();
	int qq=0;
	int k=0;
	while (t--)
	{
		printf("Case #%d: ",++qq);
		gets(s);
		int l=strlen(s);
		for (i=0;i<l;i++)
		{
			j=0;
			if (s[i]==' ') 
			{
				if (j==k) printf(" ");
				k=0;
				printf("0");
				continue;
			}
			j=s[i]-'a'+1;
			int y;
			if (j<=15)
			{
				y=(j-1)%3;
				j=ceil(j*1.0/3);
				j++;
			}
			else
			{
				if (j<=19) 
				{
					y=j-16;
					j=7;
					
				}
				else
				if (j<=22)
				{
					y=j-20;
					j=8;
					
				}
				else
				{
					y=j-23;
					j=9;
					
				}
			}
			if (j==k) printf(" ");
			k=j;
			for (int h=0;h<=y;h++)
				printf("%d",j);
		}
		printf("\n");
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值