ACM学习历程—ZOJ3878 Convert QWERTY to Dvorak(Hash && 模拟)

Description

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:

ACM学习历程—ZOJ3878 Convert QWERTY to Dvorak(Hash && 模拟)

The QWERTY Layout


ACM学习历程—ZOJ3878 Convert QWERTY to Dvorak(Hash && 模拟)

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;

这个题直接暴力手打了两张表,然后用map进行了映射。

 

代码:

#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <set>

#include <map>

#include <queue>

#include <string>



using namespace std;



char from[100] =

    {

        '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',

        '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',

        'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '|',

        'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\',

        'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"',

        'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'',

        'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',

        'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', ' '

    };

char to[100] =

    {

        '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '{', '}',

        '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '[', ']',

        '"', '<', '>', 'P', 'Y', 'F', 'G', 'C', 'R', 'L', '?', '+', '|',

        '\'',',', '.', 'p', 'y', 'f', 'g', 'c', 'r', 'l', '/', '=', '\\',

        'A', 'O', 'E', 'U', 'I', 'D', 'H', 'T', 'N', 'S', '_',

        'a', 'o', 'e', 'u', 'i', 'd', 'h', 't', 'n', 's', '-',

        ':', 'Q', 'J', 'K', 'X', 'B', 'M', 'W', 'V', 'Z',

        ';', 'q', 'j', 'k', 'x', 'b', 'm', 'w', 'v', 'z', ' '

    };



char str;



int main()

{

    //freopen("test.in", "r", stdin);

    map<char, char> Hash;

    for (int i = 0; i < 100; ++i)

        Hash[from[i]] = to[i];

    while ((str = getchar()) != EOF)

    {

        if(str == '\n')

            printf("\n");

        else

            printf("%c", Hash[str]);

    }

    return 0;

}

 

你可能感兴趣的:(convert)