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.

uva458uva458uva458uva458

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

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/27376

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 上午4:59
下一篇 2023年2月8日 上午4:59

相关推荐