Uva10082
Posted zuiaimiusi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Uva10082相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章