程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> codeforces A. IQ test 題解

codeforces A. IQ test 題解

編輯:C++入門知識

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.

Input

The 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.

Output

Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.

Sample test(s) input
5
2 4 7 8 10
output
3

本題也是很簡單的題目。尤其是使用數組來解答就很多種方法可以做出來。

但是這裡我不使用任何數組,直接查找出答案來,還是挺有意思的。

因為這樣會要求仔細保存狀態。

#include 
using 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個狀態,要作對也不容易呢。


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved