-
25-A, *1300코드포스 2021. 7. 24. 22:09
Problem - A - Codeforces
codeforces.com
문제
- 순열 $a_{1}a_{2}...a_{n},\ (3 \leq n \leq 100)$에서 evenness(홀수 인지 짝수인지)가 다른 원소 하나의 index?
$O(n)$
홀수, 짝수 각각 가장 늦게 나오는 값의 index 를 저장한다
123456789101112131415161718192021222324252627282930#include <bits/stdc++.h>#define endl "\n"using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int n;cin >> n;int last_odd_ind = 0;int last_even_ind = 0;int cnt_even = 0;int tmp;for(int i = 1; i <= n; i++){cin >> tmp;if(tmp%2) last_odd_ind = i;else {last_even_ind = i;cnt_even++;}}if(cnt_even == 1) cout << last_even_ind << endl;else cout << last_odd_ind << endl;return 0;}cs'코드포스' 카테고리의 다른 글
82-A, *1100 (0) 2021.07.25 1366-B, *1300 (0) 2021.07.24 467-B, *1100 (0) 2021.07.24 1327-A, *1100 (0) 2021.07.24 1335-C, *1100 (0) 2021.07.23