题目描述

小红学会了很多英文单词,妈妈为了帮小红加强记忆,拿出纸、笔,把 N 个单词写在纸上的一行里,小红看了几秒钟后,将这张纸扣在桌子上。妈妈问小红:“你能否将这 N 个单词按照字典排列的顺序,从小到大写出来?”小红按照妈妈的要求写出了答案。现在请你编写程序帮助妈妈检查小红的答案是否正确。注意:所有单词都由小写字母组成,单词两两之间用一个空格分隔。

输入

输入包含两行。

第一行仅包括一个正整数N(0<N≤26)。

第二行包含N个单词,表示妈妈写出的单词,两两之间用一个空格分隔。

单个单词长度不超过1010。

输出

输出仅有一行。针对妈妈写出的单词,按照字典排列的顺序从小到大排列成一行的结果,每个单词后带一个空格。

样例输入

4
city boy tree student

样例输出

boy city student tree 
 1 #define UnQuestion3
 2 #ifdef Question3
 3 
 4 #define UnDebug
 5 
 6 #ifdef Debug
 7 #include <ctime>
 8 #endif
 9 
10 #include <iostream>
11 #include <queue>
12 #include <string>
13 
14 using namespace std;
15 
16 void addWords(string str);
17 void SortWords();
18 priority_queue<string, vector<string>, greater<string>> que;
19 
20 int main()
21 {
22 #ifdef Debug
23     freopen("in.txt", "r", stdin);
24     clock_t start, finish;
25     double totaltime;
26     start = clock();
27 #endif
28 
29     int N;
30     char *str;
31     str = new char[1010];
32     cin >> N;
33     while (N--)
34     {
35         cin >> str;
36         addWords(str);
37     }
38     SortWords();
39     delete[] str;
40 
41 #ifdef Debug
42     finish = clock();
43     totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
44     cout << "Time : " << totaltime * 1000 << "ms" << endl;
45     system("pause");
46 #endif
47     return 0;
48 }
49 
50 void addWords(string str)
51 {
52     que.push(str);
53 }
54 void SortWords()
55 {
56     bool ok = 0;
57     while (!que.empty())
58     {
59         if (ok)
60         {
61             cout << " " << que.top();
62             que.pop();
63         }
64         else
65         {
66             cout << que.top();
67             que.pop();
68             ok = 1;
69         }
70         
71     }
72     cout << endl;
73 }
74 
75 #endif
View Code

 

posted on 2019-05-23 17:11  jephsdge  阅读(287)  评论(0)    收藏  举报