智能T9英文输入法

智能T9英文输入法

Time Limit:1s Memory Limit:1000k
Total Submit:1556 Accepted:534
下载样例程序(PE)
下载样例程序(ELF)


Problem

某款新型手机为了方便用户,希望开发一种新的英文输入法.要求在输入英文的时候输入法不但能够做到自动联想,还能进行自动

纠错.譬如用户希望输入hello这个单词,他应该输入43556,但是他不小心输入了46556.输入法发现词库中找不到任何匹配的单词,

于是尝试把6纠正为3,这便是纠错功能.现在需要你来开发这个输入法的核心部分.

给出词库和用户的输入,请你依次给出适合的单词.

2 A B C 
3 D E F
4 G H I
5 J K L
6 M N O
7 P Q R S
8 T U V
9 W X Y Z

注意:1和0没有对应的字母,但是1和0也有可能出现.

Input

该题含有多组测试数据。

每组数据第一行是一个整数n(1<=n<=100),表示词库中的单词个数.

接下来n行每行是一个词库中的单词.单词只包含大写字母,长度不会超过10.不会出现两个相同的单词.

最后一行是一个数字串表示用户的输入.输入的长度不会超过10.

Output

对于每组测试数据的输出,包含四个部分.

首先输出完全符合输入的单词.

然后是根据联想得到的单词,即前缀部分完全符合输入的单词.

接下来输出纠正一个按键之后完全符合输入的单词.

然后是纠正一个按键之后联想得到的单词.

每部分如果有多个匹配,则按字典顺序输出.

保证不会出现无解情况.

Sample Input

6
BVUJMEE
MUTKOE
BTVLOE
ATVKEI
EVTJNJHF
OVVLMFAABC
288563

Sample Output

BTVLOE
BVUJMEE
MUTKOE
OVVLMFAABC

C的解答和结果

#include <stdio.h>
#include <string.h>
struct Node
{
    char input[15];
    char word[15];
};
char CodeTable[26] =
{
    '2', '2', '2',
    '3', '3', '3',
    '4', '4', '4',
    '5', '5', '5',
    '6', '6', '6',
    '7', '7', '7', '7',
    '8', '8', '8',
    '9', '9', '9', '9'
};
struct Node *PWords[100];
void OutputFit(int N, char* Input)
{
    int i;
    char *p, *q;
    for(i = 0; i < N; i++){
        p = Input;  q = PWords[i]->input;
        while(*p && *q){
            if(*p < *q) return;
            if(*p > *q) break;
            p++;    q++;
        }
        if(*p == 0) puts(PWords[i]->word);
    }
}
void OutputSimilar(int N, char* Input, int pos)
{
    int i;
    char temp[15];
    strcpy(temp, Input);
    for(i = 2; i <= 9; i++){
        if('0' + i == Input[pos]){
            if(Input[pos+1] != 0) OutputSimilar(N, Input, pos+1);
        }else if('0' + i != temp[pos]){
            temp[pos] = '0' + i;
            OutputFit(N, temp);
        }
    }
}
int main()
{
    int N;
    struct Node Words[100], *temp;
    int i, j, cmp, count;
    char *p, *q, Input[15];
    while(1){
        scanf("%d", &N);
        if(N == 0) break;
        gets(Words[0].word);
        for(i = 0; i < N; i++){
            PWords[i] = &Words[i];
            gets(Words[i].word);
            p = Words[i].word;
            q = Words[i].input;
            while(*p){
                *q = CodeTable[*p - 'A'];
                p++;    q++;
            }
            *q = 0;
        }
        for(i = 0; i < N - 1; i++){
            for(j = i + 1; j < N; j++){
                cmp = strcmp(PWords[i]->input, PWords[j]->input);
                if(cmp > 0){
                    temp = PWords[i];   PWords[i] = PWords[j];  PWords[j] = temp;
                }else if(cmp == 0){
                    cmp = strcmp(PWords[i]->word, PWords[j]->word);
                    if(cmp > 0){
                        temp = PWords[i];   PWords[i] = PWords[j];  PWords[j] = temp;
                    }
                }
            }
        }
        gets(Input);
        OutputFit(N, Input);
        count = 0;
        p = Input;
        while(*p){
            if(*p == 0 || *p == 1){
                count++;
                q = p;
            }
            p++;
        }
        if(count == 0) OutputSimilar(N, Input, 0);
        else if(count == 1){
            for(i = 2; i <=9; i++){
                *q = '0' + i;
                OutputFit(N, Input);
            }
        }
    }
    return 0;
}
超时了......
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值