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

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 78  Solved: 41
[Submit][Status][Web Board]

Description

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

Input

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

Output

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

Sample Input

123abc

Sample Output

123abccba321

HINT

分析:水题,直接正向输出后反向输出。

 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         printf("\n");
17     }
18 }
View Code

相关文章: