Input

t – the number of numbers in list, then t lines follow [t <= 10^6]. 



Each line contains one integer: N [0 <= N <= 10^6]

Output

Output given numbers in non decreasing order.

Example

Input:

5
5
3
6
7
1

Output:

1
3
5
6
7
大数据的排序,输入和输出。
一開始使用了cout,那么就超时了,后来换用printf,结果过了,速度快上五倍以上。 putchar应该更加快,然后更快的就是使用buffer了,使用函数fwrite.
本oj站点首先学到的就是数据输入输出问题了。

#include<stdio.h>
#include <iostream>
#include <algorithm>
using namespace std; int TurboSort()
{
int T = 0, num = -1, c = 0, j = 0;
scanf("%d\n", &T);
char buffer[1000000];
int *A = new int[T];
while ((c = fread(buffer, 1, 1000000, stdin)) > 0)
{
for (int i = 0; i < c; i++)
{
if (buffer[i] == '\n')
{
A[j++] = num;
num = -1;
}
else
{
if (-1 == num) num = buffer[i] - '0';
else num = num * 10 + buffer[i] - '0';
}
}
}
if (-1 != num) A[T-1] = num;
sort(A, A+T); for (int i = 0; i < T; i++)
{
printf("%d\n", A[i]);//使用cout会超时,最少慢5倍
}
delete [] A;
return 0;
}


codechef Turbo Sort 题解的更多相关文章

  1. 【CodeChef】Turbo Sort

    题目链接:Turbo Sort 用java自带O(NlogN)的排序就可以,java要特别注意输入输出.输入用BufferedReader,输出用printWriter.printWriter的速度比 ...

  2. SPOJ #500. Turbo Sort

    Sorting is not an out-dated topic. My own in-place qsort got TLE... so, I simply called stl::sort() ...

  3. Turbo Sort Add problem to Todo list Problem code: TSORT

    def heap_sort(ary): n = len(ary) first = int(n / 2 - 1) for start in range(first, -1, -1): # 3~0 rev ...

  4. Codechef Racing Horses题解

    找一个数组中两数之间最小的不同值. 思路: 1 排序 2 后前相减,比較得到最小不同值 三个数甚至很多其它数之间的不同值都是这么求了,时间效率都是O(nlgn) -- 排序使用的时间 原题: http ...

  5. LuoguP7259 [COCI2009-2010#3] SORT 题解

    Content 请编写一个"频率排序器".输入一个 长度为 \(n\) 的数列 \(A=\{a_1,a_2,\dots,a_n\}\),要求: 按照每个数的出现次数降序排列. 如果 ...

  6. codechef Arranging Cup-cakes题解

    Arranging Cup-cakes Our Chef is catering for a big corporate office party and is busy preparing diff ...

  7. Codechef Nuclear Reactors 题解

    There are K nuclear reactor chambers labelled from 0 to K-1. Particles are bombarded onto chamber 0. ...

  8. HDU 1425 sort 题解

    选择出数列中前k个最大的数. 这里由于数据特殊.所以能够使用hash表的方法: #include <cstdio> #include <algorithm> #include ...

  9. Hdoj 1425.sort 题解

    Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含 ...

随机推荐

  1. JavaScript Ajax + Promise

    AJAX 在现代浏览器上写AJAX主要依靠XMLHttpRequest对象: function success(text) { var textarea = document.getElementBy ...

  2. html中子div用了浮动怎样让父div的大小自动撑开(清除浮动)

    浮动子div撑开父div的几种方法: (1)在父div中在添加一个清除浮动的子div<div style=" clear:both;"></div>,该di ...

  3. js设计模式--鸭子类型

    1.简介 JavaScript没有提供传统面向对象语言的类式继承通过原型委托的形式实现对象与对象之间的继承没有对抽象类和接口的支持 编程语言按数据类型可分为静态类型语言和动态类型语言 变量的类型要到程 ...

  4. php接口开发--复制缩减Codeigniter的车轮

    接口需求: 输出json 单一入口 安全 http://segmentfault.com/q/1010000000143852基于token验证?session? 缓存 session cookie ...

  5. WorkerScript QML Type

    官方描述:在一个Qt Quick应用程序中可以使用线程了. Import Statement:     import QtQuick .属性:source : url信号:message(jsobje ...

  6. ZeroBraneStudio之支持GBK文件编码

    费了好大劲终于搞定了让ZBS支持打开GBK文件了.记录下过程: 看源码发现ZBS打开文件时会调用src\editor\commands.lua中的LoadFile函数,代码如下: local file ...

  7. 写个自动下载安装Ant的shell脚本【一】

    #!/bin/bash ###################################################### # file name: install_ant.sh # # f ...

  8. bzoj 2734: [HNOI2012]集合选数 状压DP

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 560  Solved: 321[Submit][Status ...

  9. POJ Code the Tree 树的pufer编号

    Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2259   Accepted: 859 Desc ...

  10. 删除数据表和清空数据表的内容(保存表结构)的SHELL脚本

    A,删除指定数据库的所有数据表 #!/bin/bash # 删除mysql中所有表 # 示例: # Usage: ./script user password dbnane # Usage: ./sc ...