• UVa10082


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

    题意:

    你在用键盘进行输入的时候会按错,输出的字母是你想要输入字母的右边一个字母或者字符。注意,显示的一定都是可见的字符。

    输入:

    一行字符串,表示显示在屏幕上的一串字符。

    输出:

    一行字符串,表示你想要输入的字符串。

    分析:

    注意到如果输入是空格的话,输出仍然是空格。由于输出都是输入的字符在键盘位置的右边一个,所以将键盘字符一次存入keybo数组里面,依次地读入字符串中每个字符,在keybo中找到该字符的位置,并输出位于keybo上一位的字符即可。

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <cmath>
     5 using namespace std;
     6 char keybo[] = "`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";
     7 void print_correct(char str[]){
     8     int len = strlen(str);
     9     int llen = strlen(keybo);
    10     for(int i = 0 ; i < len ; i++){
    11         if(str[i] == ' '){
    12             printf(" ");
    13             continue;
    14         }
    15         for(int j = 0 ; j < llen ; j++)
    16             if(str[i] == keybo[j]){
    17                 printf("%c",keybo[j - 1]);
    18                 break;
    19             }
    20     }
    21 }
    22 int main(){
    23     char str[100];
    24     while(gets(str)){
    25         print_correct(str);
    26         printf("
    ");
    27     }
    28     return 0;
    29 }
    View Code
  • 相关阅读:
    项目无法运行iPhone5模拟器
    多线程下载图片,滑动tableView崩溃--资源抢夺问题
    提醒事项 1. 冥想TX 2.下班路上听歌激励自己 3. 不戴眼镜 4. 困难任务拆解
    AutoLayout性能不如frame
    Tunnelblick 覆盖安装失败
    weakSelf 和 strongSelf
    动画
    4/16 近期状态
    知乎live 我的读书经验 总结
    C语言-第23课
  • 原文地址:https://www.cnblogs.com/cyb123456/p/5769123.html
Copyright © 2020-2023  润新知