Codeforces Round #271 (Div. 2) A. Keyboard 发表于 2019-01-29 | 分类于 Codeforces题解 http://codeforces.com/problemset/problem/474/A 题意:键盘输入有误,要么左偏一格要么右偏一格,输出正确的结果。 代码: 123456789101112131415161718192021222324252627282930313233#include <bits/stdc++.h>using namespace std;char s[123456];// 输入一个string等于输入一个char的数组char dir[42];int main() { string w[3]; w[0] = "qwertyuiop"; w[1] = "asdfghjkl;"; w[2] = "zxcvbnm,./"; scanf("%s", dir); scanf("%s", s); for (int i = 0; s[i]; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < w[j].length(); k++) { if (w[j][k] == s[i]) { // 找到s[i]这个char,方便转换 // w是一个string的数组,但是数组里的元素成了一个二维的char数组。 if (dir[0] == 'L') { // 想按w结果按了左边的q putchar(w[j][k + 1]); } else { putchar(w[j][k - 1]); } } } } } putchar('\n'); return 0;};