题解 | #WERTYU#
WERTYU
https://www.nowcoder.com/practice/0f318e6fffe3490cb700e16b65a93b1b
不需要上一行的键盘输入,即一个键可以输入两种字符时,只需要普通输入的字符就好,不需要shift输入。
暴力解:
- 把键盘存成一个数组;
- 判断当前字符是否是空格,不是则查询数组,并输出数组中该字符的上一个单元的字符;
- 是空格,则输出
#include <iostream> using namespace std; #include<cstring> char letter[47] = {'`','1','2','3','4','5','6','7','8','9','0','-','=', 'Q','W','E','R','T','Y','U','I','O','P','[',']','\\', 'A','S','D','F','G','H','J','K','L',';','\'', 'Z','X','C','V','B','N','M', ',' , '.' , '/'}; void findletter(char ch){ int i; for (i = 0; ch != letter[i] || i < strlen(letter); i++){ if (ch == letter[i]){ cout <<letter[i-1]; break; } } } int main(){ string str; while (getline(cin,str)){ int i = 0; while(str[i] !='\0'){ if (str[i] !=' '){ findletter(str[i]); } else cout <<str[i];//输出空格 i++; } } }