题解 | #字符串反转#
字符串反转
http://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04
#include <stdio.h>
#include <string.h>
int main()
{
char str[1000] = {0};
scanf("%s", str);
int len = strlen(str);
char *out = NULL;
out = (char *)malloc(len);
memset(out, 0, len+1);
for(int i = 0; i < len; i++)
{
if(str[i] >= 'a' && str[i] <= 'z')
{
out[len-1-i] = str[i]; //把输入字符串的头字符放在输出的尾部
}
}
out[len] = '\0';
printf("%s\n", out);
if(out)
{
free(out);
out = NULL;
}
return 0;
}