Description:
You are are given two sorted list of numbers (ascending order). The lists themselves are comma delimited and the two lists, are semicolon. Print out the intersection of the two sets. Input Sample:
File containing two lists of ascending order sorted integers, comma delimited, one per line. e.g.
1,2,3,4;4,5,6
7,8,9;8,9,10,11,12
Output Sample:
Print out the ascending order sorted intersection of the two lists
e.g.
4
8,9
programme I:
#使用python的list自带的函数intersection
Import Sys
if __name__ = = "__main__":
argv = sys.argv
inf = open (Argv[1], ' R ')
While True:
line = Inf.readline ()
If Len (line) = = 0:
Break
ll = Line.split (';')
S1 = Ll[0].split (', ')
S2 = ll[1].split (', ')
RL = List (set (S2). Intersection (set (S1))
print ', '. Join (RL)
Programme II:
Import Sys
if __name__ = = "__main__": argv = sys.argv
inf = open (Argv[1], ' R ')
While True:
line = Inf.readline ()
If Len (line) = = 0:
Break
ll = Line.split (';')
S1 = Ll[0].split (', ')
S2 = ll[1].split (', ')
i = 0
j = 0
RL = []
While I < Len (S1) and J < Len (S2):
Print I,s1[i]
Print J,s2[j]
if Int (s1[i]) = = Int (s2[j]):
Rl.append (S1[i])
i + 1
J + 1
elif Int (s1[i]) < int (S2[j]):
i + 1
Else
J + 1
print ', '. Join (RL)