zoukankan      html  css  js  c++  java
  • Codeforce 25A

    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.

    Examples
    input
    5
    2 4 7 8 10
    output
    3
    input
    4
    1 2 1 1
    output
    2

    题解:一组数只有一个奇数或者偶数,输出它的位置.
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 using namespace std;
    13 #define lowbit(x) (x&(-x))
    14 #define max(x,y) (x>y?x:y)
    15 #define min(x,y) (x<y?x:y)
    16 #define MAX 100000000000000000
    17 #define MOD 1000000007
    18 #define pi acos(-1.0)
    19 #define ei exp(1)
    20 #define PI 3.141592653589793238462
    21 #define INF 0x3f3f3f3f3f
    22 #define mem(a) (memset(a,0,sizeof(a)))
    23 typedef long long ll;
    24 const int N=105;
    25 const int mod=1e9+7;
    26 int a[N];
    27 int main()
    28 {
    29     int n;
    30     while(cin>>n){
    31         int i,flag1,flag2,sum1=0,sum2=0;
    32         for(i=0;i<n;i++){
    33             cin>>a[i];
    34             if(a[i]%2==0){
    35                 flag2=i+1;
    36                 sum2++;
    37             }
    38             else {
    39                 flag1=i+1;
    40                 sum1++;
    41             }
    42         }
    43         if(sum1>0&&sum2>0){
    44             if(sum1==1)   cout<<flag1<<endl;
    45             else    cout<<flag2<<endl;
    46         }
    47     }
    48     return 0;
    49 }
     
  • 相关阅读:
    Windows下PHP开启mcrypt扩展和SSL(OpenSSL)扩展支持
    MyBatis 学习笔记
    试用百度云计算平台
    TCP三次握手及四次挥手详细图解
    Java开发中的23种设计模式详解
    Extjs4.1.0_从入门到精通
    SQLite3命令操作大全
    带你了解 HBase 数据模型和 HBase 架构
    让数据库无惧灾难,华为云GaussDB同城双集群高可用方案正式发布!
    论文阅读丨神经清洁: 神经网络中的后门攻击识别与缓解
  • 原文地址:https://www.cnblogs.com/wydxry/p/7259355.html
Copyright © 2011-2022 走看看