n = 0
while True:
n += 1
line = input()
if line == "END":
break
P = [0, 0]
Dir = line[:-1].split(',')
for i in range(len(Dir)):
for j in range(len(Dir[i])):
if ord(Dir[i][j]) > 57:
k = j
t = int(Dir[i][:k])
break
if Dir[i][k:] == 'N':
P[0] += t
elif Dir[i][k:] == 'S':
P[0] -= t
elif Dir[i][k:] == 'E':
P[1] += t
elif Dir[i][k:] == 'W':
P[1] -= t
elif Dir[i][k:] == 'NE':
P[0] += t/(2**0.5)
P[1] += t/(2**0.5)
elif Dir[i][k:] == 'SE':
P[0] -= t/(2**0.5)
P[1] += t/(2**0.5)
elif Dir[i][k:] == 'NW':
P[0] += t/(2**0.5)
P[1] -= t/(2**0.5)
else:
P[0] -= t/(2**0.5)
P[1] -= t/(2**0.5)
print("Map #" + str(n))
print("The treasure is located at (%.3f,%.3f)." % (P[1], P[0]))
print("The distance to the treasure is %.3f.\n" % (P[0]**2 + P[1]**2)**0.5)
n = 0
while True:
n += 1
line = input()
if line == "END":
break
P = [0, 0]
Dir = line[:-1].split(',')
for i in range(len(Dir)):
for j in range(len(Dir[i])):
if ord(Dir[i][j]) > 57:
k = j
t = int(Dir[i][:k])
break
if Dir[i][k:] == 'N':
P[0] += t
elif Dir[i][k:] == 'S':
P[0] -= t
elif Dir[i][k:] == 'E':
P[1] += t
elif Dir[i][k:] == 'W':
P[1] -= t
elif Dir[i][k:] == 'NE':
P[0] += t/(2**0.5)
P[1] += t/(2**0.5)
elif Dir[i][k:] == 'SE':
P[0] -= t/(2**0.5)
P[1] += t/(2**0.5)
elif Dir[i][k:] == 'NW':
P[0] += t/(2**0.5)
P[1] -= t/(2**0.5)
else:
P[0] -= t/(2**0.5)
P[1] -= t/(2**0.5)
print("Map #" + str(n))
print("The treasure is located at (%.3f,%.3f)." % (P[1], P[0]))
print("The distance to the treasure is %.3f.\n" % (P[0]**2 + P[1]**2)**0.5)
應該是最後一組測資沒有空一行。
n = 0
while True:
n += 1
line = input()
if line == "END":
break
P = [0, 0]
Dir = line[:-1].split(',')
for i in range(len(Dir)):
for j in range(len(Dir[i])):
if ord(Dir[i][j]) > 57:
k = j
t = int(Dir[i][:k])
break
if Dir[i][k:] == 'N':
P[0] += t
elif Dir[i][k:] == 'S':
P[0] -= t
elif Dir[i][k:] == 'E':
P[1] += t
elif Dir[i][k:] == 'W':
P[1] -= t
elif Dir[i][k:] == 'NE':
P[0] += t/(2**0.5)
P[1] += t/(2**0.5)
elif Dir[i][k:] == 'SE':
P[0] -= t/(2**0.5)
P[1] += t/(2**0.5)
elif Dir[i][k:] == 'NW':
P[0] += t/(2**0.5)
P[1] -= t/(2**0.5)
else:
P[0] -= t/(2**0.5)
P[1] -= t/(2**0.5)
print("Map #" + str(n))
print("The treasure is located at (%.3f,%.3f)." % (P[1], P[0]))
print("The distance to the treasure is %.3f.\n" % (P[0]**2 + P[1]**2)**0.5)
應該是最後一組測資沒有空一行。
我直接丟網路上大神的AC碼也是OLE。
經過我暴力測試,測資應該有14筆。
n = 0
while True:
n += 1
line = input()
if line == "END":
break
P = [0, 0]
Dir = line[:-1].split(',')
for i in range(len(Dir)):
for j in range(len(Dir[i])):
if ord(Dir[i][j]) > 57:
k = j
t = int(Dir[i][:k])
break
if Dir[i][k:] == 'N':
P[0] += t
elif Dir[i][k:] == 'S':
P[0] -= t
elif Dir[i][k:] == 'E':
P[1] += t
elif Dir[i][k:] == 'W':
P[1] -= t
elif Dir[i][k:] == 'NE':
P[0] += t/(2**0.5)
P[1] += t/(2**0.5)
elif Dir[i][k:] == 'SE':
P[0] -= t/(2**0.5)
P[1] += t/(2**0.5)
elif Dir[i][k:] == 'NW':
P[0] += t/(2**0.5)
P[1] -= t/(2**0.5)
else:
P[0] -= t/(2**0.5)
P[1] -= t/(2**0.5)
print("Map #" + str(n))
print("The treasure is located at (%.3f,%.3f)." % (P[1], P[0]))
print("The distance to the treasure is %.3f.\n" % (P[0]**2 + P[1]**2)**0.5)
應該是最後一組測資沒有空一行。
我直接丟網路上大神的AC碼也是OLE。
經過我暴力測試,測資應該有14筆。
此題應該是嚴格檢測,最後最後不可以空行。
這題在 UVa 上面 最後要空行 不然會 Presentation error
在這裡反而最後不能空行 不然會 OLE
只能說這題剛好相反過來
或是說平常因為都不是嚴格模式所以沒差
不然平常都是 UVa 不能有空行