您的位置:首页 > 其它

UVa-10082-WERTYU

2017-01-10 18:42 363 查看
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 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. 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/

Output for Sample Input

I AM FINE TODAY.

【解析】

题目的意思就是把手放在键盘上打字不注意的话总是把所想打出的字母往右移了一位,比如我们输入的是Q变成了W,我们想输入的A变成了S。题目给出我们错的字符串叫我们输出正确的字符串。此题也涉及到了, . / 等这些字符所以我们用ascll码做肯定是不好做了,那么我们就列一个字符数组把所以涉及到的字符串放在里面然后再输出它的前一个字符那就可以了。这里还有注意的就是我们想把 '\'这个放在字符串当中我们则需要放两个\\进去。因为以\开头的为转义序列。#include<stdio.h>
#include<string.h>
int main()
{
char s[]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";//先把各个字符放入一个数组当中
int i;
char c;
while((c=getchar())!=EOF)
{
for(i=1;s[i]!='\0';i++)
{
if(s[i]==c)//找到那个字符跳出循环如果没有找到则一直到s[i]为'\0'
break;
}
if(s[i]!='\0')
{
printf("%c",s[i-1]);//已经找到了则输出前一个
}
else
{
printf("%c",c);//没有找到则直接输出
}

}
return 0;
}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: