问题:
把手放在键盘上时,稍不注意就会往右错一位。这样,输入q会变成输入w,输入j会变成输入k等。
输入一个错位后敲出的字符串(所有字母均小写),输出打字员本来想打出的句子。
输入一个错位后敲出的字符串(所有字母均小写),输出打字员本来想打出的句子。
ps. 输入保证合法,如果出现q、a、z的话则不变。
样例输入:
o s, gomr ypfsu/
o s, gomr ypfsu/
样例输出:
i am fine today.
解:
public class Main{
static char[] s = { 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', '\\', 'a', 's', 'd', 'f', 'g',
'h', 'j', 'k', 'l', 'l', ';', '\'', 'z', 'x', 'c',
'v', 'b', 'n', 'm', ',', '.', '/' };
public static void main(String[] args) throws IOException {
while (true) {
char c = (char) System.in.read();
if (c == '\r')
break;
if (c == ' ') {
System.out.print(" ");
continue;
}
int i = 0;
while (s[i] != c) {
i++;
if (i == s.length)
break;
}
if (c == 'q' || c == 'a' || c == 'z')
i++;
System.out.print(s[i - 1]);
}
}
}
447

被折叠的 条评论
为什么被折叠?



