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

  • 相关阅读:
    Spyder汉化问题
    Python配置环境变量
    Python、Spyder的环境搭建
    自然语言处理(六)词向量
    自然语言处理(五)深度学习
    自然语言处理(三)主题模型
    自然语言处理(四)统计机器翻译SMT
    自然语言处理(二) 语言模型
    自然语言处理(一)基础知识
    机器学习(九)隐马尔可夫模型HMM
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/10899107.html
Copyright © 2020-2023  润新知