题目链接:http://115.28.203.224/problem.php?cid=1010&pid=7
题目描述
所给字符串正序和反序连接,形成新串并输出
输入
多组样例输入。
任意字符串(长度<=50)
输出
字符串正序和反序连接所成的新字符串
样例输入
123abc
样例输出
123abccba321
代码
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #define maxlen 1100 5 using namespace std; 6 char str[maxlen]; 7 int main() 8 { 9 while (gets(str)) 10 { 11 int len = strlen(str); 12 for (int i = 0; i < len; ++i) 13 printf("%c", str[i]); 14 for (int i = len - 1; i >= 0; --i) 15 printf("%c", str[i]); 16 cout<<endl; 17 } 18 return 0; 19 }
本文介绍了一种通过C++实现的算法,该算法接收任意字符串作为输入,并输出由该字符串正序与反序拼接而成的新字符串。示例代码展示了如何读取字符串、计算其长度并进行正序和反序的输出。
1万+

被折叠的 条评论
为什么被折叠?



