Published:
Updated:


Solution

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C_25A {
    public static int solution(List<Integer> list) {
        int index = 1; // Numbers are numbered from 1 in the input order -> ๋ฒˆํ˜ธ๊ฐ€ 1๋ถ€ํ„ฐ ๋งค๊ฒจ์ง
        int evenPos = 0, oddPos = 0, evenCnt = 0, oddCnt = 0;

        // ์›์†Œ๊ฐ„์˜ ๊ฐ„๊ฒฉ์ด ๋‹ฌ๋ผ์ง€๋Š” index ์ฐพ๊ธฐ
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) % 2 == 0) { // index๊ฐ€ ์ง์ˆ˜
                evenCnt++; // ์ง์ˆ˜์ผ ๋•Œ ์นด์šดํŠธ (ํ™€์ˆ˜ ํ˜น์€ ์ง์ˆ˜๊ฐ€ 1์ผ ๋•Œ๋ฅผ ์œ„ํ•ด)
                evenPos = i; // ๋งˆ์ง€๋ง‰ ์œ„์น˜ ์ €์žฅ
            } else {
                oddCnt++;
                oddPos = i;
            }
        }

        // ํ™€์ง ์นด์šดํŠธ๊ฐ€ 1์ด๋ฉด ๊ทธ ์œ„์น˜๊ฐ€ ๋ฒ”์ธ์ด๊ธฐ ๋•Œ๋ฌธ์— index์— ์ €์žฅ
        if (evenCnt == 1) {
            index += evenPos;
        } else if (oddCnt == 1){
            index += oddPos;
        }

        return index;
    }

    public static void main(String[] args) throws IOException {
        List<Integer> list = new ArrayList<>();

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");

        for (int i = 0; i < n; i++) {
            list.add(Integer.parseInt(st.nextToken()));
        }

        // output
        System.out.print(solution(list));

        br.close();
    }
}

Leave a comment