-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2sum.py
48 lines (46 loc) · 817 Bytes
/
2sum.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
46
47
48
f = open("rosalind_2sum.txt",'r')
num=[]
num = f.readline()
srtd =num.strip()
srtd = map(int, srtd.split(' '))
line = srtd[0]
#print line
size = srtd[1]
#print size
out=[]
for i in range(1,line+1):
k = 0
count = 0
num = f.readline()
A = num.strip()
A = map(int, A.split(' '))
while k<size:
for j in range(k, size):
if A[k]==-A[j] and k<j:
#print "A[k]",A[k]
#print "-A[j]",-A[j]
count = 1
#if k<j:
out.append(k+1)
out.append(j+1)
break
#else:
#out.append(j)
#out.append(k)
#break
if(count):
break
k+=1
if(not(count) and k==size):
out.append(-1)
f.close()
ff = open("output8.txt",'w')
i = 0
while i< len(out):
if(out[i]==-1):
ff.write(str(out[i])+"\n")
i+=1
else:
ff.write(str(out[i])+" "+str(out[i+1])+"\n")
i+=2
ff.close()