Given is a list of
words and a lexicographical ordering according to the ascii alphabet. Your task
is to sort the words in increasing order.
Input.
The first line contains the numbers of testcases k (k
< 100). Every testcase consists of n
+ 1 (1 < n < 50000) lines. Each
line contains of a string of 10 characters. The first line of each testcase
contains n.
Output.
Output the sorted list of words.
Sample Input
2
2
helloworld
worldhello
2
aaaaaaaaaa
Aaaaaaaaaa
Sample Output
helloworld
worldhello
Aaaaaaaaaa
aaaaaaaaaa
сортировка
Воспользуемся любым
алгоритмом сортировки.
Реализация алгоритма
Для сортировки строк воспользуемся сортировкой STL.
#include <cstdio>
#include <string>
#include <algorithm>
using namespace
std;
string *s;
int i, n, k;
char line[20];
int main(void)
{
scanf("%d",&k);
while(k--)
{
scanf("%d\n",&n);
s = new string[n];
for(i = 0; i < n; i++) gets(line), s[i] =
(string)line;
sort(s,s+n);
for(i = 0; i < n; i++) puts(s[i].c_str());
delete[] s;
}
return 0;
}