Uva-10082-Problem C: WERTYU

亦凉 2022-05-27 10:08 269阅读 0赞

Problem C: WERTYU

p10082.jpg

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

  1. O S, GOMR YPFSU/

Output for Sample Input

  1. I AM FINE TODAY.

思路:普通做法:恶心的一逼

  1. #include<queue>
  2. #include<stack>
  3. #include<cmath>
  4. #include<cstdio>
  5. #include<cstring>
  6. #include<cstdlib>
  7. #include<iostream>
  8. #include<algorithm>
  9. using namespace std;
  10. int main()
  11. {
  12. char a;
  13. while(scanf("%c",&a)!=EOF)
  14. {
  15. if(a=='=')printf("-");
  16. else if(a=='-')printf("0");
  17. else if(a=='0')printf("9");
  18. else if(a=='9')printf("8");
  19. else if(a=='8')printf("7");
  20. else if(a=='7')printf("6");
  21. else if(a=='6')printf("5");
  22. else if(a=='5')printf("4");
  23. else if(a=='4')printf("3");
  24. else if(a=='3')printf("2");
  25. else if(a=='2')printf("1");
  26. else if(a=='1')printf("`");
  27. else if(a=='\\')printf("]");
  28. else if(a==']')printf("[");
  29. else if(a=='[')printf("P");
  30. else if(a=='P')printf("O");
  31. else if(a=='O')printf("I");
  32. else if(a=='I')printf("U");
  33. else if(a=='U')printf("Y");
  34. else if(a=='Y')printf("T");
  35. else if(a=='T')printf("R");
  36. else if(a=='R')printf("E");
  37. else if(a=='E')printf("W");
  38. else if(a=='W')printf("Q");
  39. else if(a=='\'')printf(";");
  40. else if(a==';')printf("L");
  41. else if(a=='L')printf("K");
  42. else if(a=='K')printf("J");
  43. else if(a=='J')printf("H");
  44. else if(a=='H')printf("G");
  45. else if(a=='G')printf("F");
  46. else if(a=='F')printf("D");
  47. else if(a=='D')printf("S");
  48. else if(a=='S')printf("A");
  49. else if(a=='/')printf(".");
  50. else if(a=='.')printf(",");
  51. else if(a==',')printf("M");
  52. else if(a=='M')printf("N");
  53. else if(a=='N')printf("B");
  54. else if(a=='B')printf("V");
  55. else if(a=='V')printf("C");
  56. else if(a=='C')printf("X");
  57. else if(a=='X')printf("Z");
  58. else printf("%c",a);
  59. }
  60. return 0;
  61. }

高级做法:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. char s[]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
  5. int main(){
  6. char c;
  7. while((c=getchar())!=EOF){
  8. int i,j;
  9. bool flag = false;
  10. for(j=0;j<strlen(s);j++)
  11. if(c==s[j]){
  12. flag=true;
  13. putchar(s[j-1]);
  14. }
  15. if(flag==false)
  16. putchar(c);
  17. }
  18. return 0;
  19. }

发表评论

表情:
评论列表 (有 0 条评论,269人围观)

还没有评论,来说两句吧...

相关阅读

    相关 uva 11490 ——Just Another Problem

    题意:刚开始并没有看懂,耐着性子硬读下去,才勉强弄懂大意,英语也要加强训练啊! 题目是说你有s行c列士兵,然后带着他们去打仗,为了虚张声势,在士兵的中间缺了两个边长为r的洞

    相关 UVA 10779 Collectors Problem(最大流)

    题意:现在有包括了Bob在内的N个小朋友,M种游戏卡片,Bob可以和其他人交换卡片,除了Bob,每个人的交换原则都是只给出自己拥有大于1的卡片,接受自己没有的卡片。的问他最后