69,371
社区成员
发帖
与我相关
我的任务
分享
#include"stdio.h"
#include"string.h"
main()
{
char st[20],cs[5][20];
int i,j,p;
printf("input country'name:\n");
for(i=0;i <5;i++)
gets(cs[i]);
printf("\n");
for(i=0;i <5;i++)
puts(cs[i]);
for(i=0;i <5;i++)
{
p=i;
strcpy(st,cs[i]);
for(j=j+1;j <5;j++) //这一句改成j=i+1
if(strcmp(cs[j],st) <0)
{
p=j;strcpy(st,cs[j]);
}
if(p!=i)
{
strcpy(st,cs[i]);
strcpy(cs[i],cs[p]);
strcpy(cs[p],st);
}
puts(cs[i]);
}
printf("\n");
}