码迷,mamicode.com
首页 > 其他好文 > 详细

Problem 002——WERTYU

时间:2014-10-30 07:10:03      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   os   ar   for   sp   div   on   

Problem 002: WERTYU

bubuko.com,布布扣

A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner.

Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control,etc.] are not represented in the input. You are to replace each letter or punction symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the output.

Sample Input

O S, GOMR YPFSU/

Output for Sample Input

I AM FINE TODAY.
 
 
 
 
CODE
#include
int main()
{
    char a;
    while((a=getchar())!=EOF)
    {
        if(a==‘`‘)printf("  ");
        else if(a==‘1‘)printf("`");
        else if(a==‘2‘)printf("1");
        else if(a==‘3‘)printf("2");
        else if(a==‘4‘)printf("3");
        else if(a==‘5‘)printf("4");
        else if(a==‘6‘)printf("5");
        else if(a==‘7‘)printf("6");
        else if(a==‘8‘)printf("7");
        else if(a==‘9‘)printf("8");
        else if(a==‘0‘)printf("9");
        else if(a==‘-‘)printf("0");
        else if(a==‘=‘)printf("-");
        else if(a==‘Q‘)printf("=");
        else if(a==‘W‘)printf("Q");
        else if(a==‘E‘)printf("W");
        else if(a==‘R‘)printf("E");
        else if(a==‘T‘)printf("R");
        else if(a==‘Y‘)printf("T");
        else if(a==‘U‘)printf("Y");
        else if(a==‘I‘)printf("U");
        else if(a==‘O‘)printf("I");
        else if(a==‘P‘)printf("O");
        else if(a==‘[‘)printf("P");
        else if(a==‘]‘)printf("[");
        else if(a==‘\\‘)printf("]");
        else if(a==‘A‘)printf("\\");
        else if(a==‘S‘)printf("A");
        else if(a==‘D‘)printf("S");
        else if(a==‘F‘)printf("D");
        else if(a==‘G‘)printf("F");
        else if(a==‘H‘)printf("G");
        else if(a==‘J‘)printf("H");
        else if(a==‘K‘)printf("J");
        else if(a==‘L‘)printf("K");
        else if(a==‘;‘)printf("L");
        else if(a==‘\‘‘)printf(";");
        else if(a==‘Z‘)printf("‘");
        else if(a==‘X‘)printf("Z");
        else if(a==‘C‘)printf("X");
        else if(a==‘V‘)printf("C");
        else if(a==‘B‘)printf("V");
        else if(a==‘N‘)printf("B");
        else if(a==‘M‘)printf("N");
        else if(a==‘,‘)printf("M");
        else if(a==‘.‘)printf(",");
        else if(a==‘/‘)printf(".");
        else if(a>=‘a‘&&a<=‘z‘)printf("  ");
        else printf("%c",a);
    }
    return 0;
}
 
MY  WAY
       这是一个说难不难,说简单不简单的题,起码对我现在的水平来说是这样的。最开始我想用数组字符串的知识,后来发现现在的自己根本驾驭不了。后来用了最笨 的方法,如上所示。但是真的心里不是滋味,头一次拿了AC却没有任何喜悦感。等到过段时间,数组和字符串完成了后,我会重新做一下这个题,重新把他用字符 串数组的知识做一遍。

Problem 002——WERTYU

标签:style   http   io   os   ar   for   sp   div   on   

原文地址:http://www.cnblogs.com/acmer-zcy/p/4061085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!