Codeforces 271 Div 2 A Keyboard

题目链接:http://codeforces.com/contest/474/problem/A

解题报告:一个矩形的键盘,上面只有规定的字符,现在按的时候总是会向某个方向按偏,也就是输入一串字符后,这串字符其实不是我要输入的字符,偏的方向只有左跟右,现在给你每次偏的方向跟输入的字符,让你求原来想要的字符串。注意不会出现按到键盘外的情况。

直接键盘上所有的字符先存到一起,然后左偏取的时候+1,右偏取的时候-1就行了。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 char str[105];
 8 int main()
 9 {
10     char ch[20];
11     char dir[200] = "qwertyuiopasdfghjkl;zxcvbnm,./";
12     while(scanf("%s",ch)!=EOF)
13     {
14         scanf("%s",str);
15         int flag = -1;
16         if(ch[0] == 'L') flag = 1;
17         int len = strlen(str),n = strlen(dir);
18         for(int i = 0;i < len;++i)
19         {
20             for(int j = 0;j < n;++j)
21             if(dir[j] == str[i])
22             {
23                 printf("%c",dir[j+flag]);
24                 break;
25             }
26         }
27         puts("");
28     }
29     return 0;
30 }        
View Code
原文地址:https://www.cnblogs.com/xiaxiaosheng/p/4009148.html