A common typing error is to place the hands on
the keyboard one row to the right of the correct
position. So ‘Q’ is typed as ‘W’ and ‘J’ is typed
as ‘K’ and so on. You are to decode a message
typed in this manner.
Input
Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except
Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp,
Control, etc.] are not represented in the input.
Output
You are to replace each letter or punction symbol by the one immediately to its left on the ‘QWERTY’
keyboard shown above. Spaces in the input should be echoed in the output.
Sample Input
O S, GOMR YPFSU/
Sample Output
I AM FINE TODAY.
就是键盘错位了,把他换回来。
做法1,像我一样傻傻的一个一个手动换掉。过程我就不详说了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
char a[1005];
int main()
{
int i, j, m, n, ans, len;
while (gets(a))
{
len = strlen(a);
for (i = 0; i < len; i++)
{
if (a[i] == '1')
a[i] = '`';
else if (a[i] == '2')
a[i] ='1' ;
else if (a[i] == '3')
a[i] = '2';
else if (a[i] == '4')
a[i] = '3';
else if (a[i] == '5')
a[i] = '4';
else if (a[i] == '6')
a[i] = '5';
else if (a[i] == '7')
a[i] = '6';
else if (a[i] == '8')
a[i] = '7';
else if (a[i] == '9')
a[i] = '8';
else if (a[i] == '0')
a[i] = '9';
else if (a[i] == '-')
a[i] = '0';
else if (a[i] == '=')
a[i] = '-';
else if (a[i] == 'W')
a[i] = 'Q';
else if (a[i] == 'E')
a[i] = 'W';
else if (a[i] == 'R')
a[i] = 'E';
else if (a[i] == 'T')
a[i] = 'R';
else if (a[i] == 'Y')
a[i] = 'T';
else if (a[i] == 'U')
a[i] = 'Y';
else if (a[i] == 'I')
a[i] = 'U';
else if (a[i] == 'O')
a[i] = 'I';
else if (a[i] == 'P')
a[i] = 'O';
else if (a[i] == '[')
a[i] = 'P';
else if (a[i] == ']')
a[i] = '[';
else if (a[i] == '\\')
a[i] = ']';
else if (a[i] == 'S')
a[i] = 'A';
else if (a[i] == 'D')
a[i] = 'S';
else if (a[i] == 'F')
a[i] = 'D';
else if (a[i] == 'G')
a[i] = 'F';
else if (a[i] == 'H')
a[i] = 'G';
else if (a[i] == 'J')
a[i] = 'H';
else if (a[i] == 'K')
a[i] = 'J';
else if (a[i] == 'L')
a[i] = 'K';
else if (a[i] == ';')
a[i] = 'L';
else if (a[i] == 39)
a[i] = ';';
else if (a[i] == 'X')
a[i] = 'Z';
else if (a[i] == 'C')
a[i] = 'X';
else if (a[i] == 'V')
a[i] = 'C';
else if (a[i] == 'B')
a[i] = 'V';
else if (a[i] == 'N')
a[i] = 'B';
else if (a[i] == 'M')
a[i] = 'N';
else if (a[i] == ',')
a[i] = 'M';
else if (a[i] == '.')
a[i] = ',';
else if (a[i] == '/')
a[i] = '.';
}
for (i = 0; i < len; i++)
cout << a[i];
cout << endl;
}
return 0;
}
方法2,把键盘从第一行到第三行一次输入进字符串里,然后判断是否需要替换(有个别字符是不能换的),然后s[i]=s[i-1];
比上面那个好多了- -方法看智商。
本文介绍了一种解决键盘错位输入问题的算法实现。通过将输入文本中的每个字符替换为QWERTY键盘上其左侧的字符来纠正错位输入。文章提供了两种解决方案:一种是手动替换每个字符;另一种是利用字符串来简化替换过程。
430

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



