zoukankan      html  css  js  c++  java
  • 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
    ",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("
    ");
    39     }
    40     return 0;
    41 }
    View Code
  • 相关阅读:
    利用calc()宽度计算做响应式布局
    设置背景图片后,使用backgroup-size出现的问题
    三、算法与控制结构
    C++数值计算
    python认识及环境变量
    Unity查找Editor下Project视图中特定的资源
    UGUI ScrollRect滑动居中CenterOnChild实现
    unity与android交互总结
    UGUI笔记
    UGUI性能优化
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4626690.html
Copyright © 2011-2022 走看看