1882 - 【C语言训练】字符串正反连接

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

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

题目输入

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

题目输出

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

输入/输出样例

输入格式

123abc

输出格式

123abccba321

C++解答

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int main()
{
	string s1,s2;
	cin >> s1;
	s2=s1;
	
	for(int i=0;i<=s1.length();++i)
	s2[i]=s1[s1.length()-i-1];
	
	cout << s1+s2;
	return 0;
}

Python解答

# coding=utf-8
str1=input()
str2=str1
for i in range(len(str1),0,-1):
    str2=str2+str1[i-1]
print(str2)