[英]fastest way to read this type of input from command line in python
I am trying to solve this TSORT and it needs a fast version of input and output,我正在尝试解决这个TSORT ,它需要一个快速版本的输入和输出,
I tried using int(raw_input())
for each line and counting sort but it was not efficient enough so is there any other way,我尝试对每一行使用int(raw_input())
并进行计数排序,但效率不够高,所以还有其他方法吗,
I tried fileinput.input()
but I cant have it end at the right time我试过fileinput.input()
但我不能让它在正确的时间结束
the input is of type :输入类型为:
5 #number of lines unto 10^6, and each value is from 0 to 10^6 3 8 9 1 7
using sys.stdin
seems to be quite a bit faster then raw_input
.使用sys.stdin
似乎比raw_input
快很多。 maybe like this也许像这样
n = int(sys.stdin.readline())
print '\n'.join(map(str, sorted(map(int, sys.stdin))))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.