题目描述
输入n个字符串(每个字符串长度不超过100个字符),按从小到达排序输出。
输入描述
第一行输入一个正整数n,下面n行输入n个字符串。
输出描述
按字符串从小到大输出n行(n个字符串)
样例输入
4
C Program
Data Structure and Algorithms
Operating System
C++ Object Oriented Program
样例输出
C Program
C++ Object Oriented Program
Data Structure and Algorithms
Operating System
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int cmp(const void * a, const void * b)
{
return strcmp(*((const char **)a), *((const char **)b));
}
int main()
{
int n;
scanf("%d", &n);
char ** str = (char **)malloc(sizeof(char *) * n);
for (int i = 0; i < n; i++)
{
str[i] = (char *)malloc(sizeof(char) * 100);
fflush(stdin);
scanf("%[^\n]", str[i]);
}
qsort(str, n, sizeof(char **), cmp);
for (int i = 0; i < n; i++)
{
printf("%s\n", str[i]);
}
return 0;
}