История изменений
Исправление kto_tama, (текущая версия) :
Выкладываю свой код:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys, array, tempfile, heapq
assert array.array('i').itemsize == 4
iters = []
f_input = open('input2.txt', 'r')
def intsfromfile(name):
f_temp = open(name, 'r')
while True:
#a = array.array('d')
a=[]
for ii in xrange(0,100000):
line = f_temp.readline()
if line != '':
a.append(long(str(line).strip()))
if not a:
break
for x in a:
yield x
f_temp.close()
iii=0
while True:
#a = array.array('d')
a=[]
for ii in xrange(0,100000):
line = f_input.readline()
if line != '':
a.append(long(str(line).strip()))
if not a:
break
f_name = 'tempfile%d' % iii
f_temp = open(f_name, 'a')
iii +=1
b = sorted(a)
for yy in b:
f_temp.write(str(yy)+'\n')
f_temp.close()
iters.append(intsfromfile(f_name))
f_output = open('output.txt', 'a')
for x in heapq.merge(*iters):
f_output.write(str(x)+'\n')
f_output.close()
Исправление kto_tama, :
Выкладываю свой код:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys, array, tempfile, heapq
assert array.array('i').itemsize == 4
iters = []
f_input = open('input2.txt', 'r')
def intsfromfile(name):
f_temp = open(name, 'r')
while True:
#a = array.array('d')
a=[]
for ii in xrange(0,100000):
line = f_temp.readline()
if line != '':
a.append(long(str(line).strip()))
if not a:
break
for x in a:
yield x
f_temp.close()
iii=0
while True:
#a = array.array('d')
a=[]
for ii in xrange(0,100000):
line = f_input.readline()
if line != '':
a.append(long(str(line).strip()))
if not a:
break
f_name = 'tempfile%d' % iii
f_temp = open(f_name, 'a')
iii +=1
b = sorted(a)
for yy in b:
f_temp.write(str(yy)+'\n')
f_temp.close()
iters.append(intsfromfile(f_name))
f_output = open('output.txt', 'a')
for x in heapq.merge(*iters):
f_output.write(str(x)+'\n')
f_output.close()
Исходная версия kto_tama, :
Выкладываю свой код:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys, array, tempfile, heapq
assert array.array('i').itemsize == 4
iters = []
f_input = open('input2.txt', 'r')
def intsfromfile(name):
f_temp = open(name, 'r')
while True:
#a = array.array('d')
a=[]
for ii in xrange(0,100000):
line = f_temp.readline()
if line != '':
a.append(long(str(line).strip()))
if not a:
break
for x in a:
yield x
f_temp.close()
iii=0
while True:
#a = array.array('d')
a=[]
for ii in xrange(0,100000):
line = f_input.readline()
if line != '':
a.append(long(str(line).strip()))
if not a:
break
f_name = 'tempfile%d' % iii
f_temp = open(f_name, 'a')
iii +=1
b = sorted(a)
for yy in b:
f_temp.write(str(yy)+'\n')
f_temp.close()
iters.append(intsfromfile(f_name))
print sys.getsizeof(iters)
f_output = open('output.txt', 'a')
for x in heapq.merge(*iters):
f_output.write(str(x)+'\n')
f_output.close()