#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define size 5
void reverseString(char* s,char* s1)
{
int i,j;
int length = strlen(s);
for (i = 0,j = length-1;i < length;i++,j--)
{
s1[i] = s[j];
}
}
int main()
{
char *s;
char *s1;
s = malloc(size * sizeof(char));
s1 = malloc(size * sizeof(char));
scanf("%s",s);
printf("O:%s\n",s);
reverseString(s,s1);
printf("R:%s\n",s1);
free(s);
free(s1);
}
复杂度分析:双字符串解法的时间复杂度为O(n);空间复杂度为O(2n);