ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 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 를 저장한다

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    #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 == 1cout << last_even_ind << endl;
        else cout << last_odd_ind << endl;
     
        return 0;

     

    '코드포스' 카테고리의 다른 글

    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

    댓글

Designed by Tistory.