zoukankan      html  css  js  c++  java
  • Uva10082

    WERTYU UVA - 10082

    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.

     1 #include<bits/stdc++.h>
     2 #define LL long long
     3 #define maxn 100100
     4 using namespace std;
     5 char s[]={"`1234567890-=QWERTYUIOP[]ASDFGHJKL;'ZXCVBNM,./"};
     6 int c;
     7 int main()
     8 {
     9     while((c=getchar())!=EOF)
    10     {
    11         int i;
    12         for(i=1;s[i]!=c;i++);//该字符找到在字母表中的位置
    13         if(i+1<=strlen(s))putchar(s[i-1]);
    14         else putchar(c);
    15     }
    16     return 0;
    17 }

    思路:

    运用常量数组,把键盘上的字符保存到数组中,注意题目要求所有字母都是大写的,TAB、BackSp、Control等不会出现在输入中。输入一个字符,输出该字符左边的字符就OK了。

    注意点:

    1.!=/==的优先级比=高,(c=getchar())!=EOF这里是先赋值再判断是否不等,所以一定要加括号。

    2.输出字符用putchar(字符);

  • 相关阅读:
    python 开源机器学习包
    linux hadoop 集群安装步骤
    bbc 大数据
    微信小程序弹出可填写框两种方法
    js 一个对象的属性名是一个变量怎么处理?
    解决微信小程序使用switchTab跳转后页面不刷新的问题
    SQL 和 NoSQL 的区别
    IndexedDB API
    jQuery jsonp跨域请求
    关于setInterval返回值问题
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/10899107.html
Copyright © 2011-2022 走看看