码迷,mamicode.com
首页 > 其他好文 > 详细

Uva10082

时间:2019-05-21 12:40:11      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:大写   label   erro   letter   tput   text   efi   优先   comm   

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了。

注意点:

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

Uva10082

标签:大写   label   erro   letter   tput   text   efi   优先   comm   

原文地址:https://www.cnblogs.com/zuiaimiusi/p/10899107.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!