例题17  年龄排序(Age Sort, UVa 11462)照从小到大的顺序输出。

【输入格式】

输入包含多组测试数据。每组数据的第一行为整数n(0<n≤2 000 000),即居民总数;下一行包含n个不小于1、不大于100的整数,即各居民的年龄。输入结束标志为n=0。

输入文件约有25MB,而内存限制只有2MB。

【输出格式】

对于每组数据,按照从小到大的顺序输出各居民的年龄,相邻年龄用单个空格隔开。



效率对比:





输入输出挂

inline int readint() {
char c = getchar();
while(!isdigit(c)) c = getchar(); int x = 0;
while(isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x;
} int buf[10]; //声明成全局变量可以减小开销
inline void writeint(int i) {
int p = 0;
if(i == 0) p++; //特殊情况:i等于0的时候需要输出0,而不是什么也不输出
else while(i) {
buf[p++] = i % 10;
i /= 10;
}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]); //逆序输出
}

1.注意3次getchar

2.注意inline

3.注意i=0;

4.注意buf的全局性

完整代码:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cctype>
#define uns unsigned
#define int64 long long
#ifdef WIN32
#define fmt64 "%I64d"
#else
#define fmt64 "%lld"
#endif
#define oo 0x13131313
using namespace std;
int n;
int Sort[200];
inline int readint()
{
char c = getchar();
while(!isdigit(c)) c=getchar();
int x = 0;
while(isdigit(c))
{
x= x*10 +c - '0';
c=getchar();
}
return x;
}
int buf[10];
inline void printfint(int i)
{
int p=0;
if(i==0) p++;
else while(i)
{
buf[p++]=i%10;
i/=10;
}
for(int j=p-1;j>=0;j--) putchar('0'+buf[j]);
}
void output()
{
int tot=0;
for(int i=1; i <= 100; i++)
for(int j=1; j <= Sort[i]; j++)
{
printfint(i);
tot++;
if(tot!=n) printf(" ");
}
printf("\n");
}
void input()
{
int temp;
while(scanf("%d",&n)!=EOF&&n!=0)
{
memset(Sort,0,sizeof(Sort));
for(int i=1; i <= n ; i++ )
{
temp=readint();
Sort[temp]++;
}
output();
}
} int main()
{
input();
return 0;
}

【输入输出挂】【Uva11462】Age Sort的更多相关文章

  1. UVA 11462 Age Sort(计数排序法 优化输入输出)

    Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ...

  2. POJ1904(有向图缩点+输入输出挂参考)

    King's Quest Time Limit: 15000MS   Memory Limit: 65536K Total Submissions: 8311   Accepted: 3017 Cas ...

  3. poj 2823 Sliding Windows (单调队列+输入输出挂)

    Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 73426   Accepted: 20849 ...

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

    B Age Sort Input: Standard Input Output: Standard Output   You are given the ages (in years) of all ...

  5. COGS 1406. 邻居年龄排序[Age Sort,UVa 11462](水题日常)

    ★   输入文件:AgeSort.in   输出文件:AgeSort.out   简单对比时间限制:1 s   内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强 ...

  6. ACM比赛(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 t ...

  7. 【UVA 11462】 Age Sort(基数排序)

    题 题意 给你最多2000000个数据,大小是1到99的数,让你排序输出. 分析 快排也可以过.不过这题本意是要基数排序(桶排序),就是读入年龄age, a[age]++,然后输出时,从1到99岁(看 ...

  8. UVa 11462 Age Sort

    解题报告:给若干个居民的年龄排序,年龄的范围在1到100之间,输入的总人数在0到200W.这题要注意的输入的文件约有25MB,而内存限制为2MB,所以如果人数是像200W这样多的话,甚至都不能把它们都 ...

  9. 11462 Age Sort(计数排序)

    内存不够用,用计数排序可以解决问题. #include<iostream> #include<cstdio> #include<cstdlib> #include& ...

随机推荐

  1. IDataParameter调用存储过程

    public string  GenerateExamePaper(string paperType, string driverID, string MacAddr)         {       ...

  2. android-sdk-windows版本号下载

    Android SDK 4.0.3 开发环境配置及执行 近期又装了一次最新版本号的ADK环境 眼下最新版是Android SDK 4.0.3 本文的插图和文本尽管是Android2.2的 步骤都是一样 ...

  3. Android应用程序绑定服务(bindService)的过程源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6745181 Android应用程序组件Serv ...

  4. ASP.NET内核几大对象、ASP.NET核心知识(7)--转载

    本文的学习流程是这样安排的. 一个简单的GDI小案例 1.说明 如果你想思考如何生成验证码,那么您第一个要解决的问题,一定是.NET动态生成图片问题. //GDI:.Net程序中进行绘图的一些类. 2 ...

  5. 利用PHP/MYSQL实现的简易微型博客(转)

    数据库:ly_php_base 表:ly_micro_blog(仅仅有一个表)字段:id,title,date,content,hits 文件: 文件 描述 default.php 默认主页.显示博文 ...

  6. fullcalendar .net版本

    实现了基本的增删改和拖拽,先记与此,抽时间继续优化和完善. 参考链接:http://www.helloweba.com/tag-fullcalendar.html 参考demo:   http://f ...

  7. Sql存储过程解密方法

    在网上查到这样一个存储过程解密的方法,用起来简单,收藏到这里: )) AS ------------------------sql2000大于40000的----------------- --原作: ...

  8. C#遍历数组

    Eg: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...

  9. java集合使用——HashMap

    在map中插入.删除和定位元素时,HashMap是最好的选择.如果要按照自然顺序或自定义顺序遍历(获取所有元素),那么treemap更好一些. 第一:构造和添加元素 HashMap map = new ...

  10. (转) 谈C/C++指针精髓

    原文:http://www.cnblogs.com/madengwei/archive/2008/02/18/1072410.html   [摘要]    指针是C和C++语言编程中最重要的概念之一, ...