UVa 11462 Age Sort

题意:从小到大排序

白书上说输入有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

 

转载于:https://www.cnblogs.com/wuyuewoniu/p/4626690.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值