Решение олимпиадных задач по информатике: Линейный футбол
Сегодня решаем олимпиадную задачу по информатике школьного этапа 2022 года. Задача: "Линейный футбол". 9 - 11 класс.
n = int(input()) players = [int(input()) for _ in range(n)] answer = '' for i in range(n): k = i while k + players[k] > -1 and k + players[k] < n: if players[k] + players[k + players[k]] != 0: k += players[k] else: answer += 'U' break if k + players[k] < 0: answer += 'L' elif k + players[k] > n - 1: answer += 'R' print(answer)
var n,i,k:integer; answer:string; players:array of integer; begin read(n); players := new integer[n]; for i := 0 to n - 1 do read(players[i]); answer := ''; for i := 0 to n - 1 do begin k := i; while (k + players[k] > -1) and (k + players[k] < n) do if players[k] + players[k + players[k]] <> 0 then k := k + players[k] else begin answer := answer + 'U'; break end; if k + players[k] < 0 then answer := answer + 'L' else if k + players[k] >= n then answer := answer + 'R'; end; write(answer); end.