http://codeforces.com/problemset/problem/474/A
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
qwertyuiop
asdfghjkl;
zxcvbnm,./
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input).
We have a sequence of characters he has typed and we want to find the original message.
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard.
It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.
Print a line that contains the original message.
R
s;;upimrrfod;pbr
allyouneedislove
解题思路:模拟手在标准键盘上面输入字符,L左移一格,R右移一格
2 #include <string.h>
3
4 char c[30] = {
5 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
6 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
7 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'
8 };
9
10 int main(){
11 int i, j, len, pos;
12 char to, str[110];
13 while(scanf("%c", &to) != EOF){
14 getchar();
15 gets(str);
16 len = strlen(str);
17 if(to == 'R'){
18 for(i = 0; i< len; i++){
19 for(j = 0; j < 30; j++){
20 if(str[i] == c[j]){
21 if(j <= 9){
22 printf("%c", c[(j + 9) % 10]);
23 }
24 else if(j <= 19){
25 printf("%c", c[(j + 19) % 20]);
26 }
27 else{
28 printf("%c", c[(j + 29) % 30]);
29 }
30 }
31 }
32 }
33 }
34 else if(to == 'L'){
35 for(i = 0; i< len; i++){
36 for(j = 0; j < 30; j++){
37 if(str[i] == c[j]){
38 if(j <= 9){
39 printf("%c", c[(j + 11) % 10]);
40 }
41 else if(j <= 19){
42 printf("%c", c[(j + 21) % 20]);
43 }
44 else{
45 printf("%c", c[(j + 31) % 30]);
46 }
47 }
48 }
49 }
50 }
51 printf(" ");
52 }
53 return 0;
54 }