ZOJ 3878Convert QWERTY to Dvorak

来源:互联网 发布:太原网站搜索引擎优化 编辑:程序博客网 时间:2024/06/15 16:48


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:

Qwerty LayoutThe QWERTY Layout
Dvorak LayoutThe 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;


分析:直接用 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 0x3f3f3f3fchar 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 OFFLINEfreopen("t.txt", "r", stdin);#endifint i, j, k, n, m;translate();while(gets(s)){for(i=0;s[i];i++){if(p.count(s[i]))cout << p[s[i]];elsecout <<s[i];}  puts("");}return 0;}


0 0
原创粉丝点击