私の解答
a, b, n = map(int, input().split())
li = [int(x) for x in input().split()]
for i in range(a-1, b):
print(li[i])
私の解答は解答例2に近いです。
解答例
values = input().split()
A = int(values[0])
B = int(values[1])
N = int(values[2])
a = [0] * N
values = input().split()
for i in range(N):
a[i] = int(values[i])
for i in range(A - 1, B):
print(a[i])
解答例2
A, B, N = map(int, input().split())
a = [int(x) for x in input().split()]
for ele in a[A-1:B]:
print(ele)
- スライスを用いた方法です。
- a[A-1:B] のような記法を「スライス」と言います。
- スライスはリストや文字列などに対して使うことができ、変数名[s:t] のように使うと、インデックスが s 以上 t 未満の要素をもったリストを取得することができます。