ZOJ 3878 Convert QWERTY to Dvorak


Convert QWERTY to Dvorak
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

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:

Qwerty Layout
The QWERTY Layout

Dvorak 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 做映射就好,主要是  kibibyte 单位的大小不知道导致数组

            越界发生 段错误。

           

1 Mebibyte = 220 字节 = 1,048,576 bytes = 1,024 kibibytes 
所以 100 kibibytes 开 1e5 数组才够。
代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;
#define N 100020
#define inf 0x3f3f3f3f
char s[N];
map<char, char> p;
void translate()
{
	p['_']='{';  p['-']='[';  p['+']='}';  p['=']=']';  p['Q']='"';
	p['q']='\'';  p['W']='<';  p['w']=',';  p['E']='>';  p['e']='.';
	p['R']='P';  p['r']='p';  p['T']='Y';  p['t']='y';  p['Y']='F';
	p['y']='f';  p['U']='G';  p['u']='g';  p['I']='C';  p['i']='c';
	p['O']='R';  p['o']='r';  p['P']='L';  p['p']='l';  p['{']='?';
	p['[']='/';  p['}']='+';  p[']']='=';  p['S']='O';  p['s']='o';
	p['D']='E';  p['d']='e';  p['F']='U';  p['f']='u';  p['G']='I';
	p['g']='i';  p['H']='D';  p['h']='d';  p['J']='H';  p['j']='h';
	p['K']='T';  p['k']='t';  p['L']='N';  p['l']='n';  p[':']='S';
	p[';']='s';  p['"']='_';  p['\'']='-';  p['Z']=':';  p['z']=';';
	p['X']='Q';  p['x']='q';  p['C']='J';  p['c']='j';  p['V']='K';
	p['v']='k';  p['B']='X';  p['b']='x';  p['N']='B';  p['n']='b';
	p['<']='W';  p[',']='w';  p['>']='V';  p['.']='v';  p['?']='Z';
	p['/']='z';
}
int main()
{
#ifdef OFFLINE
	freopen("t.txt", "r", stdin);
#endif
	int i, j, k, n, m;
	translate();
	while(gets(s))
	{
		for(i=0;s[i];i++){
			if(p.count(s[i]))
				cout << p[s[i]];
			else
				cout <<s[i];
		}
		  puts("");
	}
	return 0;
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值