题解 | #字符串排序#
字符串排序
http://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include<stdio.h>
#include<string.h>
int main(void)
{
char stringBuff[1000][101];
char buff[101] = {0};
int n = 0;
while(~scanf("%d",&n))
{
for(int i=0; i<n; i++)
{
scanf("%s",stringBuff[i]);
}
for(int i=0; i<n-1; i++)
{
for(int j=0; j<n-1-i; j++)
{
if(strcmp(stringBuff[j], stringBuff[j+1]) > 0)
{
strcpy(buff, stringBuff[j]);
strcpy(stringBuff[j], stringBuff[j+1]);
strcpy(stringBuff[j+1], buff);
}
}
}
for(int i=0; i<n; i++)
{
printf("%s",stringBuff[i]);
printf("\n");
}
}
return 0;
}