好玩的编程游戏网站
发现一个很有意思的网站,https://www.codingame.com/
用程序代码玩游戏,解决问题。
今天做了个简单的问题。飞船要紧急迫降,为了避免撞到山上,每飞一轮,要用激光炮轰击高度最高的山峰。降低高度在降落过程中如果撞山就算失败。试了几把才成功,完成之后看其他高手的答案,居然可以只用一条命令就解决的。
下面是我的答案:
import sys
import math
# The while loop represents the game.
# Each iteration represents a turn of the game
# where you are given inputs (the heights of the mountains)
# and where you have to print an output (the index of the mountain to fire on)
# The inputs you are given are automatically updated according to your last actions.
# game loop
h_max=0
i_max=0
while True:
for i in range(8):
mountain_h = int(input()) # represents the height of one mountain.
if mountain_h>h_max:
h_max=mountain_h
i_max = i
#print('hmax is '+str(h_max)+';mountain '+str(i_max)+' is highest',file=sys.stderr, flush=True)
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
# The index of the mountain to fire on.
print(str(i_max))
h_max=0
i_max=0
#cn #whalepower #lifestyle #cn-reader #cryptocurrency #zzan #dblog #diamondtoken #marlians #upfundme #actnearn