文章

145

粉丝

143

获赞

21

访问

38.8k

头像
后缀子串排序 题解:C题解
P1294 上海交通大学机试题
发布于2024年2月22日 21:59
阅读数 273

#include <stdio.h>
#include <string.h>

void Sort(char a[][100],int n)
{
	int i,j;
	char t[100];
	for(i = 0; i < n-1; i++)
		for(j = 1; j < n-i; j++)
			if(strcmp(a[j],a[j-1]) < 0)
			{
				strcpy(t,a[j]);
				strcpy(a[j],a[j-1]);
				strcpy(a[j-1],t);
			}
}

int main()
{
	char s[100],a[100][100];
	while(scanf("%s",s) != EOF)
	{
		int j,i = 0;
		char *p = s;
		while(*p)
		{
			strcpy(a[i],p);
			p++;
			i++;
		}
		Sort(a,i);
		for(j = 0; j < i; j++)
			printf("%s\n",a[j]);
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发