我有一个矩形的三个顶点,需要找到第四个顶点,并且我需要为N个矩形找到缺失的顶点。
不幸的是,我无法弄清楚如何在第一个矩形之后分配顶点 :/。
以下是输入示例文本文件:
2 # '2' is the number of rectangles.
5 5 # (x1, y1)
5 7 # (x2, y2)
7 5 # (x3, y3)
30 20 # (x1, y1)
10 10 # (x2, y2)
10 20 # (x3, y3)
# (there could be more '**vertices**' and more than '**2**' cases)
以下是我的方法:
import sys
def calculate(num):
x1 = lines[n].split()[0]
y1 = lines[n].split()[1]
x2 = lines[n+1].split()[0]
y2 = lines[n+1].split()[1]
x3 = lines[n+2].split()[0]
y3 = lines[n+2].split()[1]
print x1, y1
print x2, y2
print x3, y3
#Planning to write codes for calculation & results below inside this function.
readlines = sys.stdin.readlines() # reads
num = int(lines[0]) # assigns the number of cases
for i in range(0, num):
item += 1
calculate(item) # Calls the above function
当我运行这段代码时,会得到以下结果:
5 5
5 7
7 5
5 7
7 5
30 20
我希望得到的是:
5 5
5 7
7 5
30 20
10 10
10 20
itertools
ж–ҮжЎЈйЎөйқўдёӯеұ•зӨәзҡ„grouper
ж–№жі•пјҢдҪ еҸҜд»ҘиҪ»жқҫпјҲдё”й«ҳж•Ҳең°пјүе°Ҷж–Ү件еҲҶжҲҗеӨ§е°Ҹдёәдёүзҡ„еқ—иҝӣиЎҢеӨ„зҗҶгҖӮ - Frerich Raabe