zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    linux运维、架构之路-Kubernetes离线、二进制部署集群
    linux运维、架构之路-Kubernetes集群部署
    创建SpringMVC项目过程
    Spring AOP使用方式
    Java动态代理
    Java工厂模式解耦 —— 理解Spring IOC
    Neural Turing Machine
    小米路由器mini刷锐捷
    目前深度学习开源数据集整理
    Spring编译后没有xml配置文件解决方法
  • 原文地址:https://www.cnblogs.com/cyb123456/p/5769123.html
Copyright © 2011-2022 走看看