#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void Swap(char* p,char* q)
{
char c = 0;
while (p <= q)
{
c = *p;
p = q;
q = c;
p++;
q–;
}
}
void Fac_arrange(char str)
{
char p;
char q;
p = str;
q = str;
while(*q)
{
q++;
}
Swap(p, q - 1);
while (*p != ‘\0’)
{
q = p;
while (*q != ’ '&& *q != ‘\0’)
{
q++;
}
Swap(p, q - 1);
p = q;
if (*p == ’ ')
{
p++;
}
}
}
int main(void)
{
char str[100] = " ";
gets_s(str);
Fac_arrange(str);
puts(str);
system(“pause”);
return 0;
}
将一个字符串中的单词逆序
最新推荐文章于 2023-01-08 13:40:09 发布
本文介绍了一种使用C语言实现的字符串排列算法,通过自定义的Swap和Fac_arrange函数,实现了字符串中字符的重新排列。该算法首先将字符串中的所有字符进行交换,然后逐个字符地继续这一过程,直到整个字符串被完全重新排列。
695

被折叠的 条评论
为什么被折叠?



