您的位置:首页 > 其它

WERTYU

2015-07-22 16:34 330 查看
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

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.

Output

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/

Sample Output

I AM FINE TODAY.

就是键盘错位了,把他换回来。

做法1,像我一样傻傻的一个一个手动换掉。过程我就不详说了。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
char a[1005];
int main()
{
    int i, j, m, n, ans, len;
    while (gets(a))
    {
        len = strlen(a);
        for (i = 0; i < len; i++)
        {
            if (a[i] == '1')
                a[i] = '`';
            else if (a[i] == '2')
                a[i] ='1' ;
            else if (a[i] == '3')
                a[i] = '2';
            else if (a[i] == '4')
                a[i] = '3';
            else if (a[i] == '5')
                a[i] = '4';
            else if (a[i] == '6')
                a[i] = '5';
            else if (a[i] == '7')
                a[i] = '6';
            else if (a[i] == '8')
                a[i] = '7';
            else if (a[i] == '9')
                a[i] = '8';
            else if (a[i] == '0')
                a[i] = '9';
            else if (a[i] == '-')
                a[i] = '0';
            else if (a[i] == '=')
                a[i] = '-';
            else if (a[i] == 'W')
                a[i] = 'Q';
            else if (a[i] == 'E')
                a[i] = 'W';
            else if (a[i] == 'R')
                a[i] = 'E';
            else if (a[i] == 'T')
                a[i] = 'R';
            else if (a[i] == 'Y')
                a[i] = 'T';
            else if (a[i] == 'U')
                a[i] = 'Y';
            else if (a[i] == 'I')
                a[i] = 'U';
            else if (a[i] == 'O')
                a[i] = 'I';
            else if (a[i] == 'P')
                a[i] = 'O';
            else if (a[i] == '[')
                a[i] = 'P';
            else if (a[i] == ']')
                a[i] = '[';
            else if (a[i] == '\\')
                a[i] = ']';
            else if (a[i] == 'S')
                a[i] = 'A';
            else if (a[i] == 'D')
                a[i] = 'S';
            else if (a[i] == 'F')
                a[i] = 'D';
            else if (a[i] == 'G')
                a[i] = 'F';
            else if (a[i] == 'H')
                a[i] = 'G';
            else if (a[i] == 'J')
                a[i] = 'H';
            else if (a[i] == 'K')
                a[i] = 'J';
            else if (a[i] == 'L')
                a[i] = 'K';
            else if (a[i] == ';')
                a[i] = 'L';
            else if (a[i] == 39)
                a[i] = ';';
            else if (a[i] == 'X')
                a[i] = 'Z';
            else if (a[i] == 'C')
                a[i] = 'X';
            else if (a[i] == 'V')
                a[i] = 'C';
            else if (a[i] == 'B')
                a[i] = 'V';
            else if (a[i] == 'N')
                a[i] = 'B';
            else if (a[i] == 'M')
                a[i] = 'N';
            else if (a[i] == ',')
                a[i] = 'M';
            else if (a[i] == '.')
                a[i] = ',';
            else if (a[i] == '/')
                a[i] = '.';
        }
        for (i = 0; i < len; i++)
            cout << a[i];
        cout << endl;
    }
    return 0;
}


方法2,把键盘从第一行到第三行一次输入进字符串里,然后判断是否需要替换(有个别字符是不能换的),然后s[i]=s[i-1];

比上面那个好多了- -方法看智商。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: