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