uva10082 - WERTYU
题目信息
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 }