2780 ZZWYYQWZHZ
题目描述 Description
可爱的小管在玩吹泡泡。忽然,他想到了一种排序。。。。。。。
输入描述 Input Description
第一行输入n,表示有n个数。(n>=20)
以下n行输入n个数,表示要排序的数(数字长度不超过200)。
输出描述 Output Description
有n行,即这些数从小到大的排序。
样例输入 Sample Input
5
1
2
3
4
5
样例输出 Sample Output
1
2
3
4
5
数据范围及提示 Data Size & Hint
n<=50
每个数字长度不超过200.
对输入的数进行排序,和普通的排序不同的在于,可能输入的是大数据,所以输入的数据保持要用字符形式;
这一题,最近学STL的优先队列,就拿来练练手了;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #include <queue> 5 #include <stdio.h> 6 #include <string.h> 7 using namespace std; 8 struct node 9 { 10 char Str[300]; 11 int Len; 12 friend bool operator <(node aa,node bb)/*小于号重载*/ 13 { 14 if(aa.Len>bb.Len)return 1; 15 else if(aa.Len<bb.Len)return 0; 16 else 17 { 18 int Len=aa.Len; 19 int i; 20 for(i=0;i<Len;i++) 21 { 22 if(aa.Str[i]==bb.Str[i])continue; 23 else if(aa.Str[i]>bb.Str[i])return 1; 24 else return 0; 25 } 26 } 27 } 28 }; 29 int main() 30 { 31 int N,i; 32 while(scanf("%d",&N)!=EOF) 33 { 34 priority_queue<node>ID; 35 node STR; 36 int sign=0; 37 for(i=0;i<N;i++) 38 { 39 scanf(" %s",STR.Str); 40 STR.Len=strlen(STR.Str); 41 ID.push(STR); 42 } 43 for(i=0;i<N;i++) 44 { 45 printf("%s ",ID.top().Str); 46 ID.pop(); 47 } 48 } 49 return 0; 50 }