0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニング「配列の書き換え Python3編」

Last updated at Posted at 2022-12-14

私の解答

a, b, n = map(int, input().split())
li = [int(x) for x in input().split()]
for i in range(n):
    if li[i] == a:
        li[i] = b
        print(li[i])
    else:
        print(li[i])

解答例1

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, ele in enumerate(a):
    if ele == A:
        a[i] = B

for ele in a:
    print(ele)

解答例2

A, B, N = map(int, input().split())
a = [int(x) for x in input().split()]

for i, ele in enumerate(a):
    if ele == A:
        a[i] = B

for ele in a:
    print(ele)
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?