题目连接:http://acm.tju.edu.cn/toj/showp.php?pid=13681368. WERTYU
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 3158 Accepted Runs: 1346
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 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. You are to replace each letter or punctuation 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/
Output for Sample Input
I AM FINE TODAY.
Source: Waterloo Local Contest Jan. 17, 2001
题解:一个水题却教会了我如何使用getchar(), 在所有的读入数据的时候都是在没打回车之前数据存在缓存中,回车后开始将缓存中的数据读入到程序中,所以这个题,可以一个一个获取每个字符,然后处理,然后输出
代码中还有个细节就是\是一个转移字符,而\\表示的是一个代表\的字符,它只占一个char的空间
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std; int main()
{
char s[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./0";
int i , c;
while((c = getchar())!=EOF)
{
int i;
for( i = ;i < strlen(s) ;i++)
{
if(s[i]==c){ printf("%c",s[i-]); break ;}
}
if(i==strlen(s)) printf("%c", c);
}
return ;
}