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

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

时间:2015-05-02 20:40:57      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

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:

技术分享

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;

这个题直接暴力手打了两张表,然后用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;
}

 

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

标签:

原文地址:http://www.cnblogs.com/andyqsmart/p/4472454.html

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