#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
void strshot(char * str[]) //冒泡法排序字符串 //本题无用
{
for(int i=0;i<3;i++)
{
char * s= str[i];
for(int j=0;j<strlen(s)-1;j++)
{
for(int k=0;k<strlen(s)-1-j;k++)
{
if(s[k]>s[k+1])
{
char t=s[k];
s[k]=s[k+1];
s[k+1]=t;
}
}
}
}
}
void strshot2(char * str[]) // 字符数组排序
{
for(int i=0;i<2;i++)
{
for(int j=0;j<2-i;j++)
{
if(strcmp(str[j],str[j+1])>0)
{
char * temp=(char *)malloc(sizeof(char)*100);
strcpy(temp,str[j]),strcpy(str[j],str[j+1]),strcpy(str[j+1],temp);
}
}
}
}
int main()
{
char * str[3]; //定义 指针数组
for(int i=0;i<3;i++)
{
str[i]=(char *)malloc(sizeof(char)*100); //定义字符串
gets(str[i]);
}
strshot2(str);
for(int i=0;i<3;i++)
{
puts(str[i]);
}
}
0.0分
0 人评分