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, N. N 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
题意就是如题,应该不看都能看懂,就是平常手机输入法,注意空格用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;
}