【输入输出挂】【Uva11462】Age Sort
例题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的更多相关文章
- 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 ...
- POJ1904(有向图缩点+输入输出挂参考)
King's Quest Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 8311 Accepted: 3017 Cas ...
- poj 2823 Sliding Windows (单调队列+输入输出挂)
Sliding Window Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 73426 Accepted: 20849 ...
- Uva-------(11462) Age Sort(计数排序)
B Age Sort Input: Standard Input Output: Standard Output You are given the ages (in years) of all ...
- COGS 1406. 邻居年龄排序[Age Sort,UVa 11462](水题日常)
★ 输入文件:AgeSort.in 输出文件:AgeSort.out 简单对比时间限制:1 s 内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强 ...
- 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 ...
- 【UVA 11462】 Age Sort(基数排序)
题 题意 给你最多2000000个数据,大小是1到99的数,让你排序输出. 分析 快排也可以过.不过这题本意是要基数排序(桶排序),就是读入年龄age, a[age]++,然后输出时,从1到99岁(看 ...
- UVa 11462 Age Sort
解题报告:给若干个居民的年龄排序,年龄的范围在1到100之间,输入的总人数在0到200W.这题要注意的输入的文件约有25MB,而内存限制为2MB,所以如果人数是像200W这样多的话,甚至都不能把它们都 ...
- 11462 Age Sort(计数排序)
内存不够用,用计数排序可以解决问题. #include<iostream> #include<cstdio> #include<cstdlib> #include& ...
随机推荐
- python os模块文件相关
使用前 import os导入模块 os模块: os.sep 可以取代操作系统特定的路径分割符 os.linesep 字符串给出当前平台使用的行终止符.例如,Windows使用'\r\n ...
- oracle安装、配置、卸载、错误解决
oracle安装卸载的帖子很多,这里整理出一份,都只是给出一个链接,忘了时可以自己看看.哈哈,其实我也觉得已经不会忘了,被这个鸡毛问题困了两天,修改控制文件.环境变量.注册表什么的都不能解决问题,最后 ...
- 如何在WP8模拟器中连接本地的web服务
这个问题困扰了很久,查找答案一度找偏方向. 其实连接web服务对于wp7不是问题,因为wp7使用的网络就是本机的网络,但是到了wp8模拟器,纯粹的虚拟机,独立的设备,也就有了自己的网络连接,要当做虚拟 ...
- YII Framework学习教程-YII的Model-开发规范-路径别名-命名空间
到这里,大概的YII开发已经基本可以,但是下面要将的所有课程,学完之后可以让你更爱YII.下面的教程是讲的MVC的M,model.数据,业务,代码的集中地区.所以开始之前,学学开发规范-路径别名-命名 ...
- asp.net js 获取服务器控件值
最近在弄js 但是设计到获取服务器控件的值,有点模糊.百度查了资料都达不到效果.现在看看这个,希望朋友们能用上!! <asp:Label ID="lbDepartName" ...
- EasyUI TextBox的keypress
关于EasyUI TextBox的事件好像不多,像keypress,keydown在textbox的事件里都没有,所以要用这些事件要采取一些特殊的方法,今天用到了这些就记录一下,有两种方法, 第一种: ...
- Log4Net 的简要配置
引用log4net.dll AssemblyInfo.cs中 [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyF ...
- Mysql 6.7.7 + EntityFramework 5.0 Code First 不能 Update-Database 问题的解决
1.修改 Migrations/Configuration.cs 文件 namespace DataModel.Migrations { using System; using System.Data ...
- Ubuntu中找到并杀死僵尸进程
Ubuntu中产生zombie进程让人很懊恼啊.Windows中在任务管理器里直接找到无响应的进程并结束他就行了,但是ubuntu中需要用命令去解决. System information as of ...
- SqlBulkCopy 类
1.SqlBulkCopy 简介 Microsoft SQL Server 提供一个称为 bcp 的流行的命令提示符实用工具,用于将数据从一个表移动到另一个表(表既可以在同一个服务器上,也可以在不同 ...