
大學程式檢定CPE 2012/12/18 Jolly Jumpers
題目來源:https://zerojudge.tw/ShowProblem?problemid=d097
解題的方法很多,SET、MAP,或是建立ARRAY都可以,每次相減求出的差值得絕對值,重複驗證有沒有在範圍限制內及有沒有重複出現,直到結束。
以下附上本題程式碼,如果還有任何問題請在下面留言,或是直接寄信給我囉。
def check():
try:
while True:
a = list(map(int , input().split()))
arr = [i for i in range(0,a[0])]
t = False
for i in range(2 , len(a)):
if abs(a[i] - a[i - 1]) >= len(arr) or abs(a[i] - a[i - 1]) == 0 or arr[abs(a[i] - a[i - 1])] != abs(a[i] - a[i - 1]):
print("Not jolly")
t = True
break
arr[abs(a[i] - a[i - 1])] = 0;
if t == False:
print("Jolly")
except EOFError:
pass
check()
沒有留言:
張貼留言