这是一个google code jam中的简单题目,感觉比较实用,large date已经accept、地址 http://code.google.com/codejam/contest/dashboard?c=351101#s=p2
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 press 22
. 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
Input | Output |
4 | Case #1: 44 444 |
#include<stdio.h>
#include<string.h>
typedef struct{
char c;
int pos;
int click;
}node;
node arr[200];
char ch[1010];
int main()
{
int n,t=1,len,i,j,k;
FILE *file;
for(i='a',len=0,k=2;i<'s';i++)
{
arr[i].c=i;
arr[i].pos=len;
arr[i].click=k;
len++;
if(3==len)len=0,k+=1;
}
arr['s'].c='s',arr['s'].pos=3,arr['s'].click=7;
for(i='t',len=0,k=8;i<'z';i++)
{
arr[i].c=i;
arr[i].pos=len;
arr[i].click=k;
len++;
if(3==len)len=0,k+=1;
}
arr['z'].c='z',arr['z'].pos=3,arr['z'].click=9;
arr[' '].c=' ',arr[' '].pos=0,arr[' '].click=0;
freopen("C:\\Users\\think\\Desktop\\int.txt","r",stdin);
file=freopen("C:\\Users\\think\\Desktop\\output.txt","w",stdout);
scanf("%d",&n);
getchar();
while(n--)
{
gets(ch);
fprintf(file,"Case #%d: ",t++);
len=strlen(ch);
for(i=0;i<=arr[ch[0]].pos;i++)fprintf(file,"%d",arr[ch[0]].click);
for(i=1;i<len;i++)
{
if(arr[ch[i]].click==arr[ch[i-1]].click)
{
fprintf(file," ");
}
for(j=0;j<=arr[ch[i]].pos;j++)fprintf(file,"%d",arr[ch[i]].click);
}
fprintf(file," ");
}
return 0;
}