T9 Spelling

本文探讨了GoogleCodeJam中的一个简单题目,主题围绕如何将字母与电话键盘按键进行有效映射,以简化信息传递过程。通过详细解释按键分配规则,以及提供示例输入和输出,本文为解决类似问题提供了清晰的指导路径。

这是一个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;
}


为了满足下载语法和拼写检查工具的需求,可以考虑以下几个选项,这些工具不仅提供语法和拼写检查功能,而且部分工具还支持文档无障碍性检查,适合不同场景下的使用需求: 1. **Microsoft Accessibility Checker** 是一个集成在 Microsoft Office 套件中的工具,它可以帮助用户检查文档中的无障碍性问题,虽然主要不是语法或拼写检查工具,但它有助于确保文档对所有用户都是可访问的 [^1]。 2. **Adobe Accessibility Checker** 类似于 Microsoft 的工具,它被集成在 Adobe Acrobat 中,用于检查 PDF 文档的无障碍性。对于需要确保文档对视觉障碍者友好的用户来说,这是一个有用的工具 。 3. **Grammarly** 是一款广受欢迎的语法和拼写检查工具,它不仅可以在浏览器中作为插件使用,还可以作为独立的应用程序下载安装。Grammarly 能够提供实时的语法、拼写以及风格建议,帮助用户提高写作质量。 4. **LanguageTool** 是一个开源的语法和拼写检查工具,支持多种语言,包括但不限于英语、德语、法语等。它可以作为浏览器插件、桌面应用程序以及API接口使用,非常适合需要跨平台支持的用户。 5. **Hemingway Editor** 是一款专注于提高文本清晰度和可读性的编辑器,它能够高亮显示复杂的句子结构,帮助作者简化语言表达。尽管它的主要目标不是语法检查,但对于希望提高文章可读性的作者来说,这是一个不错的选择。 以下是使用 Python 编写的简单示例,展示如何利用 `language_tool_python` 库来实现基本的语法和拼写检查功能: ```python import language_tool_python # 初始化 LanguageTool 对象 tool = language_tool_python.LanguageTool(&#39;en-US&#39;) # 要检查的文本 text = "This is a test sentense." # 执行检查 matches = tool.check(text) # 输出检查结果 for match in matches: print(f"Message: {match.message}") print(f"Suggested correction: {match.replacements}") ``` 此代码片段展示了如何初始化 LanguageTool 对象并检查一段文本中的语法和拼写错误,同时输出错误信息及建议的更正方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值