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 }
     
  • 相关阅读:
    14.会场安排问题(L4)
    图形化调试工具DDD
    sking
    全排列
    DNS
    一种排序
    多边形重心问题
    街区最短路径问题
    Fibonacci数
    python url解析
  • 原文地址:https://www.cnblogs.com/wydxry/p/7259355.html
Copyright © 2011-2022 走看看