Convert QWERTY to Dvorak

来源:互联网 发布:dota2淘宝店 编辑:程序博客网 时间:2024/06/16 12:33

Convert QWERTY to Dvorak

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;doeNfk Gq.d slpt a X,dokt vdtnsaoheKjd yspps,glu pgld; aod yso kd;kgluZ1234567890`~!@#$%^&*()}"']_+-=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`~!@#$%^&*()+_-={}[]:"'<>,.?/|ABCDEFuvwxyzAXJE>Ugk,qf;

Think:直接暴力,第一个键盘为输入,第二个键盘相应位置为输出

#include <stdio.h>#include <string.h>#include <stdlib.h>int main(void){    //freopen("out", "w", stdout);    char a[128];    for (int i = 0; i < 128; i++)        a[i] = i;    a['-'] = '[';    a['='] = ']';    a['['] = '/';    a[']'] = '=';    a['p'] = 'l';    a['o'] = 'r';    a['i'] = 'c';    a['u'] = 'g';    a['y'] = 'f';    a['t'] = 'y';    a['r'] = 'p';    a['e'] = '.';    a['w'] = ',';    a['q'] = '\'';    a['a'] = 'a';    a['s'] = 'o';    a['d'] = 'e';    a['f'] = 'u';    a['g'] = 'i';    a['h'] = 'd';    a['j'] = 'h';    a['k'] = 't';    a['l'] = 'n';    a[';'] = 's';    a['\''] = '-';    a['.'] = 'v';    a['/'] = 'z';    a[','] = 'w';    a['n'] = 'b';    a['b'] = 'x';    a['v'] = 'k';    a['c'] = 'j';    a['x'] = 'q';    a['z'] = ';';    a['Q'] = '"';    a['W'] = '<';    a['E'] = '>';    a['{'] = '?';    a['}'] = '+';    a['_'] = '{';    a['+'] = '}';    a[':'] = 'S';    a['"'] = '_';    a['Z'] = ':';    a['<'] = 'W';    a['>'] = 'V';    a['?'] = 'Z';    char x;    while (scanf("%c", &x) == 1)    {        if (x >= 'A' && x <= 'Z'            && !(x == 'Q' || x == 'W' || x == 'E' || x == 'Z'))            printf("%c", a[(int)(x + 32)] - 32);        else            printf("%c", a[(int)x]);    }    return 0;}
0 0
原创粉丝点击