Convert QWERTY to Dvorak(map)

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比较简单,注意键盘上的 | ,因为输入的是有效的字符,所以两个 | 才表示一个有效字符,还有换行字符‘\n’,空格字符,注意着几个不要遗漏,这题在POJ上如果用gets输入的话提交后会出现编译错误,所以我才换的以下的输入方式。
AC代码如下:

#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include <iostream>
#include<algorithm>
using namespace std;
map<char,char>dic;
int main()
{
	char a;
	dic['~'] = '~';
    dic['`'] = '`';
    dic['1'] = '1';
    dic['!'] = '!';
    dic['2'] = '2';
    dic['@'] = '@';
    dic['3'] = '3';
    dic['#'] = '#';
    dic['4'] = '4';
    dic['$'] = '$';
    dic['5'] = '5';
    dic['%'] = '%';
    dic['6'] = '6';
    dic['^'] = '^';
    dic['7'] = '7';
    dic['&'] = '&';
    dic['8'] = '8';
    dic['*'] = '*';
    dic['9'] = '9';
    dic['('] = '(';
    dic['0'] = '0';
    dic[')'] = ')';
    dic['_'] = '{';
    dic['-'] = '[';
    dic['+'] = '}';
    dic['='] = ']';
    dic['Q'] = '"';
    dic['q'] = '\'';

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

    dic['A'] = 'A';
    dic['a'] = 'a';
    dic['S'] = 'O';
    dic['s'] = 'o';
    dic['D'] = 'E';
    dic['d'] = 'e';
    dic['F'] = 'U';
    dic['f'] = 'u';
    dic['G'] = 'I';
    dic['g'] = 'i';
    dic['H'] = 'D';
    dic['h'] = 'd';
    dic['J'] = 'H';
    dic['j'] = 'h';
    dic['K'] = 'T';
    dic['k'] = 't';
    dic['L'] = 'N';
    dic['l'] = 'n';
    dic[':'] = 'S';
    dic[';'] = 's';
    dic['"'] = '_';
    dic['\''] = '-';
    
    dic['Z'] = ':';
    dic['z'] = ';';
    dic['X'] = 'Q';
    dic['x'] = 'q';
    dic['C'] = 'J';
    dic['c'] = 'j';
    dic['V'] = 'K';
    dic['v'] = 'k';
    dic['B'] = 'X';
    dic['b'] = 'x';
    dic['N'] = 'B';
    dic['n'] = 'b';
    dic['M'] = 'M';
    dic['m'] = 'm';
    dic['<'] = 'W';
    dic[','] = 'w';
    dic['>'] = 'V';
    dic['.'] = 'v';
    dic['?'] = 'Z';
    dic['/'] = 'z';
    dic['\n'] = '\n';
    dic[' '] = ' ';
    /*
    char a[200000];
    while(gets(a))
    {
    	int len=strlen(a);
    	for(int i=0;i<len;i++)
    		printf("%c",dic[a[i]]);
		printf("\n);
    }
    */
	while( (a = getchar()) != EOF)
	{
		printf("%c",dic[a]);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值