作业帮 > 综合 > 作业

ACM的问题Problem C: WERTYUA common typing error is to place the

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/03/29 15:05:40
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;

}



#include <stdio.h>
#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