time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 n space-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
input
4
1 2 1 1
output
2

解题报告:水题。。

。给你一列数,当中仅仅有一个数的奇偶性和其它数不同,输出它所在的位置。直接暴力扫一遍,记录最后一个奇数和偶数的位置,并记录奇数和偶数的个数。就可以。

AC代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int a[105]; int main()
{
#ifdef sxk
freopen("in.txt","r",stdin);
#endif
int n;
while(scanf("%d",&n)!=EOF)
{
int ans1 = 0, ans2 = 0, x, y;
for(int i=0; i<n; i++){
cin>>a[i];
if(a[i]&1) {
ans1 ++;
x = i+1;
}
else{
ans2 ++;
y = i+1;
}
}
if(ans1>ans2) cout<<y<<endl; //推断条件也可换成ans1 == 1
else cout<<x<<endl;
}
return 0;
}

Codeforces Beta Round #25 (Div. 2)--A. IQ test的更多相关文章

  1. Codeforces Beta Round #25 (Div. 2 Only)

    Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A #include<bits/stdc++.h ...

  2. codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/25/A题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数.C++代码: #include ...

  3. Codeforces Beta Round #25 (Div. 2 Only) A. IQ test【双标记/求给定数中唯一的奇数或偶数】

    A. IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  4. Codeforces Beta Round #25 (Div. 2 Only)E. Test

    E. Test time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  5. Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland

    D. Roads not only in Berland time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces Beta Round #25 (Div. 2 Only) C. Roads in Berland

    C. Roads in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  8. Codeforces Beta Round #49 (Div. 2)

    Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...

  9. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

随机推荐

  1. Spark(五) -- Spark Streaming介绍与基本执行过程

    Spark Streaming作为Spark上的四大子框架之一,肩负着实时流计算的重大责任 而相对于另外一个当下十分流行的实时流计算处理框架Storm,Spark Streaming有何优点?又有何不 ...

  2. Solr报错Index locked for write for core '***'. Solr now longer supports forceful unlocking via 'unlockOnStartup'

    unlockOnStartup 告知 Solr 忽略在多线程环境中用来保护索引的锁定机制.在某些情况下,索引可能会由于不正确的关机或其他错误而一直处于锁定,这就妨碍了添加和更新.将其设置为 true ...

  3. Jacoco覆盖率工具使用之maven篇

    说明 之前的文章已经介绍过如何使用apacheant 执行jacoco工具,下面开始介绍如何使用maven使用jacoco工具. 1.首先新建一个maven项目       如图所示:        ...

  4. MAC下MySQL忘记初始密码

    MAC下MySQL忘记初始密码的解决方法分享给大家,供大家参考,具体内容如下 从官网安装好MySQL的dmg后. 1 设置mysql命令 从终端输入 ? 1 mysql --version 若显示版本 ...

  5. 乌云主站所有漏洞综合分析&乌云主站漏洞统计

    作者:RedFree 最近的工作需要将乌云历史上比较有含金量的漏洞分析出来,顺便对其它的数据进行了下分析:统计往往能说明问题及分析事物的发展规律,所以就有了此文.(漏洞数据抓取自乌云主站,漏洞编号从1 ...

  6. mui.ajax返回type为abort

    最近在使用h5和mui开发app,发现mui.ajax有一个小bug 情况一: 参数和请求路径无误,但是总是调起失败的回调函数,打印出 type=abort (终止请求) 原因: mui.ajax默认 ...

  7. 【Oracle】查找每期数据都存在的产品

    现在存在以下数据 如上图:A01与A02同时存在201710.201711.201712中 我们现在要将其查找出来 如果上图的表结构如下: 那么查询的SQL如下: SELECT DISTINCT CO ...

  8. lucene 索引中文档的属性建立与不建立带来的影响总结

    索引中文档的属性建立与不建立带来的影响总结   1.依据文档的某属性去查找索引的话,只会返回带有此属性(如果你对当前属性设定了条件,那么需要满足当前条件)的所有文档,没有建立此属性的文档是不会在返回结 ...

  9. C++语言基础(3)-类和对象

    类是创建对象的模板,一个类可以创建多个对象,每个对象都是类类型的一个变量:创建对象的过程也叫类的实例化.每个对象都是类的一个具体实例(Instance),拥有类的成员变量和成员函数. 一.类的定义 一 ...

  10. 美团HD(6)-添加搜索遮罩

    DJSelectCityViewController.m /** SearchBar开始编辑 */ - (void)searchBarTextDidBeginEditing:(UISearchBar ...