浙江省赛2015 _ J - Convert QWERTY to Dvorak -> ZOJ 3878

2023-05-16

模拟水题
题目:ZOJ 3878

Edward, a poor copy typist, is a user of the Dvorak Layout. But now he has only a QWERTY Keyboard with a broken Caps Lock key, so Edward never presses the broken Caps Lock key. Luckily, all the other keys on the QWERTY keyboard work well. Every day, he has a lot of documents to type. Thus he needs a converter to translate QWERTY into Dvorak. Can you help him?
The QWERTY Layout and the Dvorak Layout are in the following:
The QWERTY Layout
The QWERTY Layout
这里写图片描述
The Dvorak Layout
Input
A QWERTY document Edward typed. The document has no more than 100 kibibytes. And there are no invalid characters in the document.
Output
The Dvorak document.
Sample Input
Jgw Gqm Andpw a H.soav Patsfk f;doe
Nfk Gq.d slpt a X,dokt vdtnsaohe
Kjd yspps,glu pgld; aod yso kd;kgluZ
1234567890
`~!@#$%^&*()}”’]_+-=ZQqWEwe{[|
ANIHDYf.,bt/
ABCDEFuvwxyz

Sample Output
Hi, I’m Abel, a Dvorak Layout user.
But I’ve only a Qwerty keyboard.
The following lines are for testing:
1234567890
`~!@#$%^&*()+_-={}[]:”’<>,.?/|
ABCDEFuvwxyz
AXJE>Ugk,qf;

思路:用switch判断,将每个QWERTY键盘符号转换成Dvorak键盘符号。注意 : getline(cin,s)接收一行string,while(getline(cin,str[cnt++]));接收多行string

代码实现:

#include<bits/stdc++.h>
using namespace std;

void solve(char s){
    switch(s){
        //1
        case '_':cout<<'{';break;
        case '-':cout<<'[';break;
        case '+':cout<<'}';break;
        case '=':cout<<']';break;

        //2
        case 'Q':cout<<'"';break;
        case 'q':cout<<'\'';break;
        case 'W':cout<<'<';break;
        case 'w':cout<<',';break;
        case 'E':cout<<'>';break;
        case 'e':cout<<'.';break;
        case 'R':cout<<'P';break;
        case 'r':cout<<'p';break;
        case 'T':cout<<'Y';break;
        case 't':cout<<'y';break;
        case 'Y':cout<<'F';break;
        case 'y':cout<<'f';break;
        case 'U':cout<<'G';break;
        case 'u':cout<<'g';break;
        case 'I':cout<<'C';break;
        case 'i':cout<<'c';break;
        case 'O':cout<<'R';break;
        case 'o':cout<<'r';break;
        case 'P':cout<<'L';break;
        case 'p':cout<<'l';break;
        case '{':cout<<'?';break;
        case '[':cout<<'/';break;
        case '}':cout<<'+';break;
        case ']':cout<<'=';break;

        //3
        case 'S':cout<<'O';break;
        case 's':cout<<'o';break;
        case 'D':cout<<'E';break;
        case 'd':cout<<'e';break;
        case 'F':cout<<'U';break;
        case 'f':cout<<'u';break;
        case 'G':cout<<'I';break;
        case 'g':cout<<'i';break;
        case 'H':cout<<'D';break;
        case 'h':cout<<'d';break;
        case 'J':cout<<'H';break;
        case 'j':cout<<'h';break;
        case 'K':cout<<'T';break;
        case 'k':cout<<'t';break;
        case 'L':cout<<'N';break;
        case 'l':cout<<'n';break;
        case ':':cout<<'S';break;
        case ';':cout<<'s';break;
        case '"':cout<<'_';break;
        case '\'':cout<<'-';break;

        //4
        case 'Z':cout<<':';break;
        case 'z':cout<<';';break;
        case 'X':cout<<'Q';break;
        case 'x':cout<<'q';break;
        case 'C':cout<<'J';break;
        case 'c':cout<<'j';break;
        case 'V':cout<<'K';break;
        case 'v':cout<<'k';break;
        case 'B':cout<<'X';break;
        case 'b':cout<<'x';break;
        case 'N':cout<<'B';break;
        case 'n':cout<<'b';break;
        case '<':cout<<'W';break;
        case ',':cout<<'w';break;
        case '>':cout<<'V';break;
        case '.':cout<<'v';break;
        case '?':cout<<'Z';break;
        case '/':cout<<'z';break;


        default : cout<<s;

    }
}
int main(int argc, char const *argv[])
{
    int cnt = 0;
    string str[200];
    while(getline(cin,str[cnt++]));
    //cout<<"cnt : "<<cnt<<endl;
    for (int i = 0; i < cnt; ++i)
    {
        int length = str[i].size();
        for(int j=0;j<length;j++)
            solve(str[i][j]);
        if(i!=cnt-1)cout<<endl;
    }
    return 0;
}

小结:模拟水题,刚开始忘记str设为数组了,得了个Segmentation Fault ,然后Presentation Error,因为换行,输入的最后一行没有换行,就不需要输出换行,注意 : 输出结果保持与输入一致。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

浙江省赛2015 _ J - Convert QWERTY to Dvorak -> ZOJ 3878 的相关文章

随机推荐