uva10082 - WERTYU

本文介绍了解码因键盘输入位置偏移而产生的错误文本的方法。通过将每个字符替换为QWERTY键盘上其左侧的字符来还原原始消息。示例输入和输出展示了如何纠正此类常见打字错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目信息

Problem C:  WERTYU

 

 

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 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. You are to replace each letter or punction 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/

 

Output for Sample Input

 

I AM FINE TODAY.

 

 1 源代码:
2
3 #include<iostream>
4
5 #include<string>
6
7 using namespace std;
8
9 string str1="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
10
11 string str2;
12
13 char a[128];
14
15
16
17 void Init()
18
19 {//建立按键的映射,有一点是:可以推出实际字符串中不会包括每行按钮的最后一个按钮
20
21 //如=,\,'或/
22
23 for(int i=1;i<str1.length();++i)
24
25 {
26
27 a[str1[i]]=str1[i-1];
28
29 }
30
31 a[' ']=' ';
32
33 }
34
35 int main()
36
37 {
38
39 Init();
40
41 while(getline(cin,str2))
42
43 {
44
45 for(int i=0;i<str2.length();++i)
46
47 {
48
49 cout<<a[str2[i]];
50
51 }
52
53 cout<<endl;
54
55 }
56
57 //system("pause");
58
59 return 0;
60
61 }

 

 

转载于:https://www.cnblogs.com/redlight/archive/2012/02/14/2351388.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值