WERTYU, UVa10082

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 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/
Sample Output
I AM FINE TODAY.

题意:

把手放在键盘上时,稍不注意就会往右错一 位。这样,输入Q会变成输入W,输入J会变成输 入K等。
输入一个错位后敲出的字符串(所有字母均 大写),输出打字员本来想打出的句子。输入保 证合法,即一定是错位之后的字符串。例如输入中不会出现大写字母A。

AC代码1:(比较复杂的)


#include<stdio.h>
#include<string.h>
int main()
{
 char c;
 while((c = getchar())!=EOF)
 {
  switch(c)
  {
   case'W':
    printf("Q");
    break;
    case'E':
     printf("W");
     break;
     case'R':
     printf("E");
     break;
     case'T':
     printf("R");
     break;
     case'Y':
     printf("T");
     break;
     case'U':
     printf("Y");
     break;
     case'I':
     printf("U");
     break;
     case'O':
     printf("I");
     break;
     case'P':
     printf("O");
     break;
     case'[':
     printf("P");
     break;
     case']':
     printf("[");
     break;
     case'\\':
     printf("]");
     break;
     case'S':
     printf("A");
     break;
     case'D':
     printf("S");
     break;
     case'F':
     printf("D");
     break;
     case'G':
     printf("F");
     break;
     case'H':
     printf("G");
     break;
     case'J':
     printf("H");
     break;
     case'K':
     printf("J");
     break;
     case'L':
     printf("K");
     break;
     case';':
     printf("L");
     break;
     case'\'':
     printf(";");
     break;
     case'X':
     printf("Z");
     break;
     case'C':
     printf("X");
     break;
     case'V':
     printf("C");
     break;
     case'B':
     printf("V");
     break;
     case'N':
     printf("B");
     break;
     case'M':
     printf("N");
     break;
     case',':
     printf("M");
     break;
     case'.':
     printf(",");
     break;
     case'/':
     printf(".");
     break;
     case'1':
     printf("`");
     break;
     case'2':
     printf("1");
     break;
     case'3':
     printf("2");
     break;
     case'4':
     printf("3");
     break;
     case'5':
     printf("4");
     break;
     case'6':
     printf("5");
     break;
     case'7':
     printf("6");
     break;
     case'8':
     printf("7");
     break;
     case'9':
     printf("8");
     break;
     case'0':
     printf("9");
     break;
     case'-':
     printf("0");
     break;
     case'=':
     printf("-");
     break;
     default :
     printf("%c",c);
     break;
     
  }
  
 }
}

AC代码2:(正常思路)
#include<stdio.h>
#include<string.h>
int main()
{
 char c;
 char str[]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;''ZXCVBNM,./";
 while((c=getchar())!=EOF)
 {
  int i,flag=1;
  for(i=1;str[i];i++)
  {
   if(c==str[i])
   {
    printf("%c",str[i-1]);
    flag=0;
    break;
   }
  }
 }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值