• 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
  • 相关阅读:
    android 样式开发
    Android studio 开发环境搭建
    nodejs+express 4.x笔记
    C#: switch语句的重构『网摘』
    从实例谈OOP、工厂模式和重构
    ASP.NET FileUpload 上传文件类型验证
    asp.net 网页中播放 flash 和flv
    数据库设计中主键问题
    修改Sqlserver实例默认排序规则
    查看sqlserver被锁的表以及如何解锁
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4626690.html
Copyright © 2020-2023  润新知