Kattis Run Time Error
Verfasst: Dienstag 1. Februar 2022, 15:56
Hallo,
ich habe vor kurzem angefangen Aufgaben auf Kattis zu bearbeiten. Nun hänge ich bei der folgenden Aufgabe fest.
https://open.kattis.com/pro ... narea
Der Code funktioniert innerhalb von PyCharm, allerdings bekomme ich bei Kattis einen RunTimeError, was ich leider nicht verstehe. Kann mir bitte jemand einen Tipp geben.
P.S: Generelle Tipps zum 'pythonic way' sind natürlich auch herzlich willkommen 
ich habe vor kurzem angefangen Aufgaben auf Kattis zu bearbeiten. Nun hänge ich bei der folgenden Aufgabe fest.
https://open.kattis.com/pro ... narea
Der Code funktioniert innerhalb von PyCharm, allerdings bekomme ich bei Kattis einen RunTimeError, was ich leider nicht verstehe. Kann mir bitte jemand einen Tipp geben.
Code: Alles auswählen
# ProblemID: polygonarea
# Difficulty: 3.1
# date: 31JAN2022
import sys
import math
def parse_input():
"""reads data and gives back a list of polygons each containing a list of coordinates"""
lines = [line.split() for line in sys.stdin.readlines()]
lines = [[int(x) for x in line] for line in lines]
idx = 0
polygons = []
while lines[idx][0] != 0:
anz_dots = lines[idx][0]
coordinates = [[int(x) for x in lines[i]] for i in range(idx + 1, idx + anz_dots + 1)]
polygons.append(coordinates)
idx = idx + anz_dots + 1
return polygons
def solution(data):
"""calculates area according to the shoelace formula"""
for polygon in data:
z1 = [polygon[i][0] for i, _ in enumerate(polygon)]
z1.append(z1[0])
z2 = [polygon[i][1] for i, _ in enumerate(polygon)]
z2.append(z2[0])
s1 = sum([math.prod(x) for x in list(zip(z1, z2[1:]))])
s2 = sum([math.prod(x) for x in list(zip(z1[1:], z2))])
area = (s1 - s2) / 2
if area < 0:
print(f'CW {-area:.1f}')
else:
print(f'CCW {area:.1f}')
return -1
polygons = parse_input()
solution(polygons)
