Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
InputThe first line contains integer n (3?≤?n?≤?100) — amount of numbers in the task. The second line contains nspace-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
OutputOutput index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Sample test(s) input5 2 4 7 8 10output
3
本題也是很簡單的題目。尤其是使用數組來解答就很多種方法可以做出來。
但是這裡我不使用任何數組,直接查找出答案來,還是挺有意思的。
因為這樣會要求仔細保存狀態。
#includeusing namespace std; void IQtestEVENNESS() { int n, a, even = 0, last = -1, lastNum = 0, curNum = -1, fix = -1; cin>>n; for (int i = 1; i <= n; i++) { cin>>a; even = a % 2; if (fix != -1 && fix != even) { cout<
這裡保存了5個狀態,要作對也不容易呢。