ACM的问题Problem C: WERTYUA 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
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 14:29:12
ACM的问题Problem C: WERTYUA 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
ACM的问题
Problem C: WERTYU
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 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/
Output for Sample Input
I AM FINE TODAY.
请问我的代码错哪儿了?
#include<stdio.h>
char a[]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
int main()
{ char c;
while((c=getchar())!=EOF)
{
for(int i=1;a[i]&&a[i]!=c;i++)
if(a[i]) putchar(a[i-1]);
else putchar(c);
}
return 0;
}
ACM的问题Problem C: WERTYUA 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
#include <stdlib.h>
const char s[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
char getCorrectChar(char c)
{
\x09int i;
\x09for (i = 1; i < sizeof(s); ++ i)
\x09{
\x09\x09if (s[i] == c)
\x09\x09\x09return s[i-1];
\x09}
\x09return c;
}
int main(void)
{
\x09char c;
\x09while ((c = getchar()) != EOF)
\x09\x09putchar(getCorrectChar(c));
\x09return EXIT_SUCCESS;
}
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1023