/**************************************************************************
File name:
Author:xxx Date: 2016-12-13
Description: 输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变,
句子中单词以空格符隔开。
Funcion List:
**************************************************************************/
#include <stdio.h>
void overturn (char *p)
{
char *pre;
char *cur;
pre = p;
cur = p;
while (*p != '\0')
{
p++;
}
cur = p - 1;
char temp;
while (pre <= cur)
{
temp = *pre;
*pre = *cur;
*cur = temp;
pre++;
cur--;
}
}
void reverse (char *p)
{
char *front = p;
char *later = p;
while (*later != '\0')
{
if (*later == ' ')
{
*later = '\0';
overturn(front);
*later = ' ';
later++;
front = later;
}
else
{
later++;
}
}
overturn(front);
}
int main ()
{
char ch[50];
gets (ch);
//scanf ("%s", ch);
//printf ("%s\n", ch);
overturn (ch);
reverse (ch);
puts (ch);
//printf ("%s\n", ch);
return 0;
}
字符串翻转
最新推荐文章于 2023-03-10 22:23:00 发布