首页 > 编程语言 > 详细

问题 1755: 姓名排序 (优先队列)

时间:2019-04-21 18:35:38      阅读:158      评论:0      收藏:0      [点我收藏+]

题目链接:https://www.dotcpp.com/oj/problem1755.html

题目描述

存储一组姓名,如Apple,Tom,Green,Jack 要求按照字典序排序并显示。

输入

输入第一行为样例数m,对于每个样例,第一行为人数n,接下来有n个姓名,n不超过10,每个名字长度不超过20。

输出

对于每个样例输出排序后的结果,每行一个姓名。

样例输入
1
4
Apple
Tom
Green
Jack 
样例输出
Apple
Green
Jack
Tom

优先队列很方便

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath> 
 4 #include <string>
 5 #include <cstring>
 6 #include <map> 
 7 #include <cstdio>
 8 #include <queue>
 9 using namespace std;
10 int n,t;
11 string s;
12 int main()
13 {
14     cin>>t;
15     while(t--){
16         cin>>n;
17         priority_queue<string, vector<string> ,greater<string> > pq;
18         while(n--){
19             cin>>s;
20             pq.push(s);
21         }
22         while(pq.size()){
23             cout<<pq.top()<<endl;
24             pq.pop();
25         }
26     }
27     return 0;
28 }

 

问题 1755: 姓名排序 (优先队列)

原文:https://www.cnblogs.com/shixinzei/p/10746113.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!