您的位置:首页 > 其它

ZOJ 3878 Convert QWERTY to Dvorak

2016-04-20 13:11 411 查看
Convert QWERTY to Dvorak
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status Practice ZOJ
3878

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 做映射就好,主要是 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
;
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;
}


[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: