COGS 1406. 邻居年龄排序[Age Sort,UVa 11462]

★   输入文件:AgeSort.in   输出文件:AgeSort.out   简单对比
时间限制:1 s   内存限制:2 MB

【题目描述】

Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强的 OI型 Apple Ⅱ,可以运行C,C++,和Pascal!为了炫耀这台高端的计算机,Mr.Zero决心将邻居们的年龄(0≤Age[i]≤120)统计后进行统计。但是,古董终究是古董,Mr.Zero拥有最多n个邻居(n≤2,400,000)但是计算机所能运行程序时的内存限制竟然达到了2MB。请你帮助他设计排序他的统计数据。

【输入格式】

一行整数,表示每个邻居的年龄

【输出格式】

一行整数,为排序后的年龄;

【样例输入】

1 50 9 5 25 36

【样例输出】

1 5 9 25 36 50

【来源】

(Age Sort,UVa 11462)[数据来源,Algorithms Consult,Chen Hao]

桶排

屠龙宝刀点击就送

#include <cstdio>
int N,Age[121];

int a;
int main()
{
    freopen("AgeSort.in","r",stdin);
    freopen("AgeSort.out","w",stdout);
    while(scanf("%d",&a)!=EOF) Age[a]++;
    for(int i=0;i<=120;i++)
    {
        if(Age[i]) while(Age[i]--) printf("%d ",i);
    }
    return 0;
}
时间: 2024-08-09 22:35:24

COGS 1406. 邻居年龄排序[Age Sort,UVa 11462]的相关文章

UVA之11462 - Age Sort

[题目] You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in ascending order.

[2016-03-19][UVA][11462][Age Sort]

时间:2016-03-19 20:22:57 星期六 题目编号:[2016-03-19][UVA][11462][Age Sort] 题目大意:给定n个数字,输出排序后的数据, 分析:n<=2*1E6,多组数据,所以不能直接读取然后排序,这里的数据内容范围是1~100,则可以通过计数的方式来统计,或者自己编写读取和输出的函数来优化 方法2 #include <cstdio> #include <cstring> using namespace std; typedef lon

ACM Age Sort排序

Description Age Sort:You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in a

Uva-------(11462) Age Sort(计数排序)

B Age Sort Input: Standard Input Output: Standard Output   You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very si

UVA - 11462 - Age Sort (高效算法!!)

11462 Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in ascendi

java List 排序 Collections.sort() 对 List 排序

实体类: class User { String name; String age; public User(String name,String age){ this.name=name; this.age=age; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getName() { return name; } public

排序(sort包)

使用 sort.Interface 来排序 排序是一个在很多程序中广泛使用的操作.sort 包提供了针对任意序列根据任意排序函数原地排序的功能. 这样的设计号称并不常见.在很多语言中,排序算法跟序列数据类型绑定,排序函数跟序列元素类型绑定.但 Go 语言的 sort.Sort 函数对序列和其中元素的布局无任何要求,它使用 sort.Interface 接口来实现. 接口实现 一个原地排序算法需要知道三个信息: 序列长度 比较两个元素的含义 如何交换两个元素 所以 sort.Interface 接

[示例-NSArray排序]-根据班级、姓名和年龄排序学生信息

main: 1 #import <Foundation/Foundation.h> 2 #import "Person.h" 3 4 int main(int argc, const char * argv[]) { 5 @autoreleasepool { 6 Person *stu1=[[Person alloc]initClasses:@"iOS8" andName:@"ZXY" andAge:21]; 7 Person *st

Comparator按照姓名、年龄排序

package com.heli.compare; import java.text.Collator; import java.util.Comparator; import java.util.Locale; /**  * @desc Person类. Person实现了Comparable接口,这意味着Person本身支持排序  */ public class Person implements Comparable<Person> { int age; String name; pub