私の回答
n=int(input())
ans=0
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n):
if a[i]==b[i]:
ans+=1
print(ans)
模範解答
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = 0
for i in range(n):
if a[i] == b[i]:
ans += 1
print(ans)
- A_i == B_iである要素の個数を計算します。
- まずは 2 つの配列を用意し、入力を受け取ります。
- 次にループを用いて各要素が一緒かどうか比較し、一緒の場合は答え用の変数をカウントアップします。