码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 11462 Age Sort

时间:2015-07-07 14:40:29      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

题意:从小到大排序

白书上说输入有25MB,但是内存限制只有2MB,

用sort去写了一下,居然过了~~~~~

学了计数排序----

技术分享
 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath> 
 5 #include<stack>
 6 #include<vector>
 7 #include<map> 
 8 #include<set>
 9 #include<queue> 
10 #include<algorithm>  
11 using namespace std;
12 
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=2000005;
17 
18 int a[maxn];
19 int n;
20 
21 int main(){
22     while(scanf("%d",&n) != EOF && n){
23         for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
24         sort(a+1,a+n+1);
25         for(int i=1;i<n;i++) printf("%d ",a[i]);
26         printf("%d\n",a[n]);
27     }
28     return 0;
29 }
View Code

 

技术分享
 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath> 
 5 #include<stack>
 6 #include<vector>
 7 #include<map> 
 8 #include<set>
 9 #include<queue> 
10 #include<algorithm>  
11 using namespace std;
12 
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=1000005;
17 
18 int c[105];
19 int n;
20 
21 int main(){
22     while(scanf("%d",&n) != EOF && n){
23         memset(c,0,sizeof(c));
24         for(int i = 0;i < n;i++){
25             int x;
26             scanf("%d",&x);
27             c[x]++;
28         }
29         
30         int first = 1;
31         for(int i =0;i<=100;i++){
32             for(int j = 0;j < c[i];j++){
33                 if(!first) printf(" ");
34                 first = 0;
35                 printf("%d",i);
36             }
37         }
38         printf("\n");
39     }
40     return 0;
41 }
View Code

 

UVa 11462 Age Sort

标签:

原文地址:http://www.cnblogs.com/wuyuewoniu/p/4626690.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!