T9 Spelling

这是一个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
hi
yes
foo  bar
hello world

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

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值