uva10082 WERTYU (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 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/

Sample Output

I AM FINE TODAY.
这个题的意思是说输入一串已经往右移一位的字符串然后输出原来正确的字符串。
代码
 1 #include <iostream>
 2 //#include "fp.h"
 3 using namespace std;
 4 char s[]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
 5 main()
 6 {
 7     //fop();
 8     char c;int i;
 9     while((c=getchar())!=EOF)
10     {
11         for( i=1;s[i]&&s[i]!=c;i++);
12         if(s[i]) 
13         putchar(s[i-1]);
14         else 
15         putchar(c);
16     }
17 }
 
 

这个题要求注意的东西我觉得还挺多的,首先需要了解一下用数组去记录内容的一种方法。

for( i=1;s[i]&&s[i]!=c;i++);这一行我之前就写错把下面的一堆语句写在了这个for里面,然后我基本学完了紫书的情况下,居然还是写错了一次。。。

(这段代码是真的很强,把每个输入进来的s[i]都进行了重新的定位真的是佩服佩服)

原来不明白的条件s[i]现在也明白了,是个很巧的方法,我们没有去数究竟有多少个数在字符串数组里面,我们就用一个s[i]因为如果越界s[i]应该都是0(待实验)

其他的跟上一个题基本是一样的了。

 
 

转载于:https://www.cnblogs.com/baccano-acmer/p/9717981.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值