Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9449 | Accepted: 4515 |
Description
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 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/
Sample Output
I AM FINE TODAY.
Source
问题链接:POJ2538 ZOJ1884 UVA10082 WERTYU。
问题简述:参见上文。
问题分析:
这个问题是有关输入输出流处理和字符转换问题。将键盘上的字符放在数组中备查可以省去许多程序逻辑。
程序说明:
函数convert()封装字符转换功能,可以简化主函数的逻辑。
AC的C语言程序如下:
/* POJ2538 ZOJ1884 UVA10082 WERTYU */
#include <stdio.h>
char s[]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
#define SIZE (int)sizeof(s)
char convert(char c)
{
int i;
for(i=1; i<SIZE; i++)
if(s[i] == c)
return s[i-1];
return c;
}
int main(void)
{
char c;
while((c=getchar()) != EOF)
putchar(convert(c));
return 0;
}