uva458

本文介绍了解决UVA458问题的一种方法,该问题是将输入字符串中每个字符的ASCII值减7并输出。文章详细解释了如何使用C++的string类型及empty()函数来处理空字符串作为输入结束的条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目概述:将一串任意长度的字符串的所有字符改成ASCLL值减7之后的字符,并输出。

本题非常简单,但是要注意的一个问题是什么时候输入结束程序停止。这个问题是c++编程的一个对很多人来说普遍存在的问题。它不像c那样直接判断是不是EOF就够了。回到本题,应该能够想到这个题目的结束输出信息应该是空字符串,这个程序集中解决的就是这个,所以我们用c++字符串的string类型变量,访问empty()函数就好了。

样例输入与输出:

 

input:

1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5

1PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu5

1KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5

output: 

*CDC is the trademark of the Control Data Corporation.

*IBM is a trademark of the International Business Machine Corporation.

*DEC is the trademark of the Digital Equipment Corporation.

ContractedBlock.gifExpandedBlockStart.gifuva458
1 #include<iostream>
2 #include<string>
3  using namespace std;
4  class decoder{
5 private:
6 string line;
7
8 public :
9 int input();
10 void output();
11 };
12  int decoder::input()
13 {
14 getline(cin,line);
15 return line.empty();
16 }
17  void decoder::output()
18 {
19 int len=line.size();
20 char c;
21 for(int i=0;i<len;i++)
22 {
23 c=line[i]-7;
24 cout<<c;
25 }
26 line.clear();
27 cout<<endl;
28 }
29  int main()
30 {
31 decoder uva458;
32 while(!uva458.input())
33 {
34 uva458.output();
35 }
36 return 0;
37 }

转载于:https://www.cnblogs.com/zhwyprime/archive/2011/06/18/zhwyprime-uva458.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值