题意:给定一个键盘,然后一行字母,和一个字符,代表把那一行字母在键盘上左移还是右移一位。
析:没什么好说的,直接暴力就好。
代码如下:
#include<bits/stdc++.h> using namespace std; typedef long long LL; char s1[] = "qwertyuiop"; char s2[] = "asdfghjkl;"; char s3[] = "zxcvbnm,./"; char s[105]; int main(){ char ch; scanf("%c", &ch); scanf("%s", s); int n = strlen(s); int n1 = strlen(s1); int n2 = strlen(s2); int n3 = strlen(s3); for(int i = 0; i < n; ++i){ bool ok = false; // cout << s[i]; for(int j = 0; j < n1; ++j) if(s1[j] == s[i]){ cout << (ch == 'R' ? s1[j-1] : s1[j+1]); ok = true; break; } if(ok) continue; for(int j = 0; j < n2; ++j) if(s2[j] == s[i]){ cout << (ch == 'R' ? s2[j-1] : s2[j+1]); ok = true; break; } if(ok) continue; for(int j = 0; j < n3; ++j) if(s3[j] == s[i]){ cout << (ch == 'R' ? s3[j-1] : s3[j+1]); ok = true; break; } } return 0; }