Official
A - 唱歌の最後の行 / The Last Line of a School Song Editorial
by
A - 唱歌の最後の行 / The Last Line of a School Song Editorial
by
kyopro_friends
\(i\) 曲目の最後の行を高橋君が歌うことは、\(A_i\) が奇数であることと同値です。よって \(A_1,\dots,A_N\) の中にある奇数の個数が答えになります。
実装例 (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> a(n);
for(int i=0; i<n; i++) cin >> a[i];
int ans = 0;
for(int ai: a){
if(ai % 2 == 1){
ans++;
}
}
cout << ans << endl;
}
実装例 (Python)
N = int(input())
A = map(int, input().split())
ans = 0
for a in A:
if a % 2 == 1:
ans += 1
print(ans)
