UVA10222 Decode the Mad man【编码】

Once in BUET, an old professor had gone completely mad. He started talking with some peculiarwords. Nobody could realize his speech and lectures. Finally the BUET authority fall in great trouble.There was no way left to keep that man working in university. Suddenly a student (definitely he wasa registered author at UVA ACM Chapter and hold a good rank on 24 hour-Online Judge) createda program that was able to decode that professor’s speech. After his invention, everyone got comfortagain and that old teacher started his everyday works as before.

  So, if you ever visit BUET and see a teacher talking with a microphone, which is connected to aIBM computer equipped with a voice recognition software and students are taking their lecture fromthe computer screen, don’t get thundered! Because now your job is to write the same program whichcan decode that mad teacher’s speech!

Input

The input file will contain only one test case i.e. the encoded message.

  The test case consists of one or more words.

Output

For the given test case, print a line containing the decoded words. However, it is not so hard task toreplace each letter or punctuation symbol by the two immediately to its left alphabet on your standardkeyboard.

Sample Input

k[r dyt I[o

Sample Output

how are you


问题链接UVA10222 Decode the Mad man

问题简述:(略)

问题分析(略)

程序说明

  这是一个编码问题,键盘错位,错了2位。

  有两种方法可以实现,明显后一种方法是优化的:

  一是,做一张对照表,对于输入的字符,在表中查找,得到(计算)其编码。

  二是,事先做出编码表,对于输入的字符查一下。

题记:(略)

参考链接:(略)


AC的C++语言程序(先计算编码)如下:
/* UVA10222 Decode the Mad man */

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

char code[] = "qwertyuiop[]asdfghjkl;'zxcvbnm,.";
char decode[256];

int main()
{
    // 编码计算
    memset(decode, 0, sizeof(decode));
    for(int i=2; code[i]; i++)
        decode[(int)code[i]] = code[i - 2];

    char c;
    while((c = getchar()) != EOF) {
        if(isupper(c))
            c = tolower(c);

        if(decode[(int)c])
            putchar(decode[(int)c]);
        else
            putchar(c);
    }


    return 0;
}

AC的C++语言程序(逐个字符查找)如下:

/* UVA10222 Decode the Mad man */

#include <iostream>
#include <stdio.h>
#include <ctype.h>

using namespace std;

char code[] = "qwertyuiop[]asdfghjkl;'zxcvbnm,.";

int main()
{
    char c;
    int i;

    while((c = getchar()) != EOF) {
        if(isupper(c))
            c = tolower(c);

        for(i=2; code[i] && code[i] != c; i++)
            ;

        if(code[i])
            putchar(code[i - 2]);
        else
            putchar(c);
    }

    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值