Buenas galera!
Segue a resolução de mais um problema do Google Code Jam 2008!
#
# Google Code Jam 2008 – GCJ Beta 2008 – Triangle Trilemma – Large Input
# Copyright (C) 2009 Tiago Hillebrandt <tiagohillebrandt@gmail.com>
#
import os
f = open(“A-large-practice.in”)
def integer():
s = f.readline()
s = s.strip()
s = int(s)
return s
def array():
s = f.readline()
s = s.strip()
s = s.split()
for i in range(len(s)):
s[i] = int(s[i])
return s
def angleType(a, b, c):
if ((a == b + c) or (b == c + a) or (c == a + b)):
return ” right”
else:
if ((a > b + c) or (b > a + c) or (c > a + b)):
return ” obtuse”
else:
return ” acute”
def triangleTrilemma():
for i in range(integer()):
coords = array()
x1 = coords[0]
y1 = coords[1]
x2 = coords[2]
y2 = coords[3]
x3 = coords[4]
y3 = coords[5]
if ((x1 – x2) * (y1 – y3) == (x1 – x3) * (y1 – y2)):
triangle = “not a”
else:
a = (x1 – x2) ** 2 + (y1 – y2) ** 2
b = (x1 – x3) ** 2 + (y1 – y3) ** 2
c = (x3 – x2) ** 2 + (y3 – y2) ** 2
if ((a == b) or (b == c) or (c == a)):
triangle = “isosceles” + angleType(a, b, c)
else:
triangle = “scalene” + angleType(a, b, c)
print “Case #” + str(i + 1) + “: “ + triangle + ” triangle”
if __name__ == ‘__main__’:
triangleTrilemma()
E novamente, quem quiser baixar, clique aqui.
Um abraço e até a próxima.