Problem C: WERTYU

Problem C: WERTYU

时间: 1ms        内存:128M

描述:

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 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.

输入:

输出:

示例输入:

O S, GOMR YPFSU/

示例输出:

I AM FINE TODAY.

提示:

参考答案(内存最优[748]):

#include <stdio.h>

char *k = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";

main(){
   int i,c;
   while (EOF != (c = getchar())) {
      for (i=1;k[i] && k[i]!=c;i++);
      if (k[i]) putchar(k[i-1]); else putchar(c);
   }
}

参考答案(时间最优[0]):

#include <stdio.h>

char *k = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";

main(){
   int i,c;
   while (EOF != (c = getchar())) {
      for (i=1;k[i] && k[i]!=c;i++);
      if (k[i]) putchar(k[i-1]); else putchar(c);
   }
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注