AOJ.602 大家来找茬

大家来找茬

Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB
Total Submission: 627 Submission Accepted: 197

Description

cxlove很喜欢玩大家来找茬的游戏。
但是他对图像不敏感,他喜欢有关数字的游戏。
给n个正整数,其中有1个数和其它的n-1个数奇偶性不同。
你敢和cxlove比比吗,看谁先找出那个数。

Input

一个整数T,表示T组数据 (1<=T<=100)
对于每组数据:
一个整数n,表示n个正整数 (3<=n<=100)
n个正整数a1,a2……,an (1<=ai<=10000)
数据保证有且仅有1个数与剩下的数奇偶性不同。

Output

对于每一组数据,输出不同的数的下标,其中下标从1开始

Sample Input

2
5
1 2 3 5 7
5
2 4 6 8 1

Sample Output

2
5

题意分析

数据范围不大,可以开大数组来存储数据。然后读入一个数据,判断他是奇数还是偶数。若是奇数,奇数计数器+1,并将其数组内容置为0,反之偶数计数器+1,数组内容置为1。然后比较一下计数器大小,从数组中找出对应内容为0/1的即可。

代码总览

/*
    Title:AOJ.602
    Author:pengwill
    Date:2016-11-14
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 10005
int a1[max],a2[max];


int main()
{
    //freopen("in.txt","r",stdin);
    int cnt1,cnt2,T,n,i;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        cnt1 = cnt2 = 0;
        for(i = 0;i<n;++i){
            scanf("%d",&a1[i]);
            if(a1[i] %2 == 0){
                a2[i] = 0;
                cnt1++;
            }else{
                a2[i] = 1;
                cnt2++;
            }
        }
        if(cnt1>cnt2){
            for(i = 0;i<n;++i){
                if(a2[i] == 1){
                    printf("%d\n",i+1);
                }
            }
        }else{
            for(i = 0;i<n;++i){
                if(a2[i] == 0){
                    printf("%d\n",i+1);
                }
            }
        }
    }
    return 0;
    //fclose(stdin);
}
posted @ 2016-11-14 11:04  pengwill  阅读(122)  评论(0编辑  收藏  举报