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:
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
Sample Output
分析:直接用 map 做映射就好,主要是 kibibyte 单位的大小不知道导致数组
越界发生 段错误。
[/code]
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 |
---|
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]
相关文章推荐
- 数据结构(八皇后问题)
- AngularJS学习笔记(四) 自定义指令
- Timus 1294 Mars Satellites
- ubuntu编译安装lynx遇到错误configure: error: No curses header-files found
- android studio
- SmartForms 小技巧
- theano tutorial(十)Graph Structures
- 微信公众号命名规则将调整 全平台公众号名称唯一
- win8/8.1中如何查看及删除无线网络配置文件等
- postInvalidate postInvalidateOnAnimation 区别
- 109. Convert Sorted List to Binary Search Tree
- Caused by: java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addServlet
- 将 Book-Crossing Dataset 书籍推荐算法中 CVS 格式测试数据集导入到MySQL数据库
- UML 的基本组成
- centos安装配置hadoop超详细过程
- javaweb中两种jsp声明
- 怎样删除保存的无线上网WiFi密码
- 使用 HTML5 WebSocket 构建实时 Web 应用
- 电脑弹出磁盘空间不足怎么办
- Spring MVC 3.0版本 深入讲解