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(字符);

  • 相关阅读:
    ng-repeat高级用法
    使用 CSS3 实现超炫的 Loading(加载)动画效果
    ADO.NET访问数据库
    连接查询和分组查询
    T-SQL数据查询基础
    使用SQL语句操作数据
    使用表组织数据
    SQL Sever数据库
    使用属性升级Mybank
    C# 语法
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/10899107.html
Copyright © 2011-2022 走看看