博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2538 WERTYU(我的水题之路——键盘错位)
阅读量:4069 次
发布时间:2019-05-25

本文共 2382 字,大约阅读时间需要 7 分钟。

WERTYU
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6778   Accepted: 3152

Description

 
A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner.

Input

Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control, etc.] are not represented in the input.

Output

You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the output. 

Sample Input

O S, GOMR YPFSU/

Sample Output

I AM FINE TODAY.

Source

一个键盘错位了,每个按键均向右边移动一格,即是按键‘W’输出‘Q’,按键‘E’输出‘W’……,现在输入许多行数据,要求你将其还原成正确文字。
这道题有三种解法,应该说是三种数据结构。
1)第一想到的是MAP,但是MAP用起来可能比较消耗时间,
2)用一个字符数组直接用每一个字符作为下标,然后将正确的字符作为这个数组的元素, 我用的这种方法。
3)如Discuss中某大牛给的数组char mapi[]={'`','1','2','3','4','5','6','7','8','9','0','-','=','Q','W','E','R','T','Y','U','I','O','P','[',']','\\','A','S','D','F','G','H','J','K','L',';','\'','Z','X','C','V','B','N','M',',','.','/'};可以搜索输入字符的位置,然后再输出其前一个,这个就比较浪费时间。
4)其实还有很多很多方法的- -。。。毕竟是水题。
注意点:
1)空格' '和回车'\n'两个字符不做转换,直接输出,Shirt、Ctrl、Backspace按键也是如此。
代码(1AC):
#include 
#include
#include
char str[200];void init(){ int i; str['1'] = '`'; for (i = 2; i <= 10; i++){ str['0' + i % 10] = '0' + i - 1; } str['-'] = '0'; str['='] = '-'; str['W'] = 'Q'; str['E'] = 'W'; str['R'] = 'E'; str['T'] = 'R'; str['Y'] = 'T'; str['U'] = 'Y'; str['I'] = 'U'; str['O'] = 'I'; str['P'] = 'O'; str['['] = 'P'; str[']'] = '['; str['\\'] = ']'; str['S'] = 'A'; str['D'] = 'S'; str['F'] = 'D'; str['G'] = 'F'; str['H'] = 'G'; str['J'] = 'H'; str['K'] = 'J'; str['L'] = 'K'; str[';'] = 'L'; str['\''] = ';'; str['X'] = 'Z'; str['C'] = 'X'; str['V'] = 'C'; str['B'] = 'V'; str['N'] = 'B'; str['M'] = 'N'; str[','] = 'M'; str['.'] = ','; str['/'] = '.';}int main(void){ char ch; init(); while ((ch = getchar()) != EOF){ if (ch != ' ' && ch != '\n'){ putchar(str[ch]); } else{ putchar(ch); } } return 0;}

转载地址:http://tooji.baihongyu.com/

你可能感兴趣的文章
区块链技术让Yotta企业云盘为行政事业服务助力
查看>>
Yotta企业云盘更好的为媒体广告业服务
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>
Yotta企业云盘怎么帮助到能源化工行业
查看>>
企业云盘如何助力商业新发展
查看>>
医疗行业运用企业云盘可以带来什么样的提升
查看>>
能源化工要怎么管控核心数据
查看>>
媒体广告业如何运用云盘提升效率
查看>>
企业如何运用企业云盘进行数字化转型-实现新发展
查看>>
司法如何运用电子智能化加快现代化建设
查看>>
iSecret&nbsp;1.1&nbsp;正在审核中
查看>>
IOS开发的开源库
查看>>
IOS开发的开源库
查看>>
Jenkins - sonarqube 代码审查
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成(一)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 单机部署(二)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 高可用集群部署(三)
查看>>
Golang struct 指针引用用法(声明入门篇)
查看>>
Linux 粘滞位 suid sgid
查看>>