2013.7.15 acm_schooltraining解题报告

来源:互联网 发布:淘宝新品上架无线链接 编辑:程序博客网 时间:2024/06/04 00:53

Problem A: 【C语言训练】字符串正反连接

Description

所给字符串正序和反序连接,形成新串并输出

Input

任意字符串(长度<=50)

Output

字符串正序和反序连接所成的新字符串

Sample Input

123abc

Sample Output

123abccba321

HINT

分析:基础题,自己是用了string类,先将正的输出然后倒着再输一遍。有用STL的看着非常的简洁,见way2.
way1:
#include <iostream>#include <string.h>using namespace std;int main(){    string s;    while(getline(cin,s)){         cout<<s;         for(int i=s.length()-1;i>=0;i--)             cout<<s[i];          cout<<endl;    }    return 0;}

way2:
#include<iostream>#include<algorithm>  //reverse() 头文件using namespace std;int main(){    string s;    while(getline(cin,s)){        cout<<s;        reverse(s.begin(),s.end());        cout<<s<<endl;    }    return 0;}