WERTYU

WERTYU

时间: 1ms        内存:64M

描述:

A common typing error is to place your hands on the keyboard one row
to the right of the correct position. Then ``Q'' is typed as ``W'' and
``J'' is typed as ``K'' and so on. Your task is to decode a message typed
in this manner.

输入:

Input consists of several lines of text. Each line may contain digits, spaces, uppercase letters (except ``Q'', ``A'', ``Z''), or punctuation shown above [except back-quote (`)]. Keys labeled with words [Tab, BackSp, Control, etc.] are not represented in the input.

输出:

You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the output.

示例输入:

O S, GOMR YPFSU/

示例输出:

I AM FINE TODAY.

提示:

参考答案(内存最优[752]):

#include <stdio.h>
#include <stdlib.h>
char map[100]= {'`','1','2','3','4','5','6','7','8','9','0','-','=','Q','W','E','R','T','Y','U','I','O','P','[',']','\\','A','S','D','F','G','H','J','K','L',';','\'','Z','X','C','V','B','N','M','\,','\.','\/'};
int main()
{
    int i,j;
    char s[100];
    while(gets(s))
    {
        for(i=0; s[i]!=0; i++)
        {
            if(s[i]==' ')
                printf(" ");
            else
            {
                for(j=0;; j++)
                {
                    if(s[i]==map[j])
                    {
                        printf("%c",map[j-1]);
                        break;
                    }
                }
            }
        }
        printf("\n");
    }
    return 0;
}

参考答案(时间最优[0]):

#include <iostream>
using namespace std;
int main()
{
    string s = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
    string line;
    while(getline(cin,line))
    {
        for(int i = 0;i<int(line.length());i++)
        {
            if(line[i]==' ')
                cout<<" ";
            else
                cout<<s[s.find_first_of(line[i])-1];
        }
        cout<<endl;
    }
    return 0;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注