Traveling Frog Problem

狀態(status)

朝右or朝上

用一個變數來表示,表示下一步要往哪裡跳

Note:一開始朝右

status = 0 #朝右
if some_condition:
    if status == 0:
        status = 1 #如果原本朝右,那就改成朝上
    else:
        status = 0 #如果原本朝上,那就改成朝右

狀態(status)

朝右or朝上

用一個變數來表示,表示下一步要往哪裡跳

Note:一開始朝右

status = 0 #朝右
if some_condition:
    status = (status+1)%2

Done

a = int(input())
cor = [0,0]
status = 0
for i in range(10):
    cor[d]+=a
    if (cor[0]+cor[1]) % 3 == 2:
        status = (status+1)%2
print(cor[0],cor[1])

If you're lazy

a = int(input())
if a%3==1:
    print(5*a,5*a)
elif a%3==2:
    print(4*a,6*a)
else:
    print(10*a,0)

deck

By piepie01

deck

  • 357