-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.py
45 lines (35 loc) · 994 Bytes
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os, sys
#import numpy as np
files = [
'a_example.txt',
'b.txt',
'c.txt',
'd.txt',
'e.txt'
]
args = sys.argv[1:]
index = 0
if len(args) != 0:
file = args[0]
if file in ['a', 'b', 'c', 'd', 'e']:
index = ['a', 'b', 'c', 'd', 'e'].index(file)
elif file in ['1', '2', '3', '4', '5']:
index = ['1', '2', '3', '4', '5'].index(file)
input = 'input/' + files[index]
output_file = 'output_' + ['a', 'b', 'c', 'd', 'e'][index] + '.out'
with open(input) as f_in:
# read first line
rows, colums, miningr, maxcells = [int(x) for x in next(f_in).split()]
matrix = []
for line in f_in: # read rest of lines
matrix.append([x for x in line]) #TTTTT
def resulttofile(res):
with open(output_file, 'w') as f_out:
for item in res:
for subitem in item:
f_out.write("%s " % subitem)
f_out.write("\n")
def main():
resulttofile(matrix)
if __name__ == '__main__':
main()