【输入输出挂】【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& ...
随机推荐
- samba服务器加入域控主机所需要修改的配置文件
samba服务器加入域控主机,成为域成员,当用户访问samba服务器上的共享文件时,直接到域控主机上进行认证.samba服务器上不需要像先前一样创建系统用户,创建samba用户及密码. 1.安装环境( ...
- linux中萌翻了的cowsay命令
想要让你的linux萌翻吗? 首先需要安装cowsay软件 命令如下:sudo apt-get update;sudo apt-get install cowsay 然后对其输入命令,默认情况下,动物 ...
- CSS - 关于li中图文混排不能垂直居中的问题
图片和文字一起放在li标签下不能同时垂直居中 解决办法: 1.设置图片的position:absolute; 2.把文字加上span标签: span{ height:30px;line-heigh ...
- SQL Server两种分页的存储过程介绍
由于现在很多的企业招聘的笔试都会让来招聘的写一个分页的存储过程,有的企业甚至要求应聘者用两种方式实现分页,如果没有在实际项目中使用过分页,那么很多的应聘者都会出现一定的问题,下面介绍两种分 ...
- 0118——UILabel和导入字体
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)]; 1.设置文字颜色 label.textC ...
- 使用Win32 API 查找文件
头文件:#include <windows.h> //FindFirstFile() 获得指定目录的第一个文件 HANDLE FindFirstFile( LPCTSTR lpFileNa ...
- I - u Calculate e
Description A simple mathematical formula for e is where n is allowed to go to infinity. This can ac ...
- 图的广度、深度优先遍历 C语言
以下是老师作为数据结构课的作业的要求,没有什么实际用处和可以探讨和总结的的地方,所以简单代码直接展示. 宽度优先遍历: #include<cstdio> #include<iostr ...
- 在shell脚本中调用sqlplus
#!/bin/bash sqlplus dc_file_data_js/dc_file_data_js << EOF1 set linesize 500; set pagesize 100 ...
- djangoPOST请求403 forbidden
处理过程 网上搜索修改setting.py,在MIDDLEWARE_CLASSES增加django.middleware.csrf.CsrfResponseMiddleware 没能解决问题 有说在 ...