uva458

题目概述:将一串任意长度的字符串的所有字符改成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.
uva458
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 }

posted on 2011-06-18 10:37  风zhwy  阅读(447)  评论(0编辑  收藏  举报