| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
请教大虾们一个幼稚问题Sample Input
O S, GOMR YPFSU/
Sample Output
I AM FINE TODAY.
题目就是要求吧输入的字符串,按照键盘的位置,把输出每个字符再键盘上,左边的那个字符,遇到空格仍然打空格,我写的代码是把输入部分的每个字符转化后输出,但是输出空格的时候竟然打了换行,很是郁闷那!
下面是我的代码:
/*
WERTYU
char a[26]={'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'};
char b[10]={'1','2','3','4','5','6','7','8','9','0'};
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 digit, 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.
char a[26]={'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'};
char b[10]={'1','2','3','4','5','6','7','8','9','0'};
*/
#include <stdio.h>
#include <string.h>
char a[46]={'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',',','.','/'};
int main()
{
char s[1000];
char b[1000];
int i,j,k;
while(scanf("%s",s)==1)
{
int len=0;
k=0;
len=strlen(s);
for(i=0;i<len;i++)
{
if(s[i]==' ')
b[k++]=s[i];
else
{
for(j=1;j<46;j++)
{
if(s[i]==a[j])
b[k++]=a[j-1];
}
}
}
b[k]='\0';
for(i=0;i<k;i++)
printf("%c",b[i]);
printf("\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator