题解 | #字符串排序#
字符串排序
http://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include <stdio.h>
//冒泡排序
int sort_char(char str[][101], int n) //二维数组作为参数
{
char tmp[101] = {0};
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
if(strcmp(str[i], str[j]) > 0) //字符串比较
{
//交换字符串
strcpy(tmp, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j], tmp);
}
}
}
return 0;
}
int main()
{
int num = 0;
scanf("%d", &num);
char str[1001][101] = {0};
for(int i = 0; i < num; i++)
{
scanf("%s", str[i]);
}
sort_char(str, num);
for(int i = 0; i < num; i++)
{
printf("%s\n", str[i]);
}
return 0;
}