Age Sort UVA - 11462

问题

https://vjudge.net/problem/UVA-11462

分析

计数排序

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=100+5;
int num[maxn],t,n,kase=0;
int main(void){
    while(scanf("%d",&n)==1 && n){
        memset(num,0,sizeof(num));
        for(int i=0;i<n;++i){
            scanf("%d",&t);
            num[t]++;
        }
        bool first=true;
        for(int i=1;i<maxn;++i){
            for(int j=0;j<num[i];++j){
                if(first==true){
                    first=false;
                    printf("%d",i);
                }else printf(" %d",i);
            }
        }
        printf("\n");
    }
}
发布了180 篇原创文章 · 获赞 3 · 访问量 3484

猜你喜欢

转载自blog.csdn.net/zpf1998/article/details/104684878