Codeforces Round #713 (Div. 3)-A. Spy Detected!-题解

Codeforces Round #713 (Div. 3)-A. Spy Detected!

传送门
Time Limit: 2 seconds
Memory Limit: 256 megabytes

Problem Description

You are given an array a a a consisting of n n n ( n ≥ 3 n \ge 3 n3) positive integers. It is known that in this array, all the numbers except one are the same (for example, in the array [ 4 , 11 , 4 , 4 ] [4, 11, 4, 4] [4,11,4,4] all numbers except one are equal to 4 4 4).

Print the index of the element that does not equal others. The numbers in the array are numbered from one.

Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 100 1 \le t \le 100 1t100). Then t t t test cases follow.

The first line of each test case contains a single integer n n n ( 3 ≤ n ≤ 100 3 \le n \le 100 3n100) — the length of the array a a a.

The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( 1 ≤ a i ≤ 100 1 \le a_i \le 100 1ai100).

It is guaranteed that all the numbers except one in the a a a array are the same.

Output

For each test case, output a single integer — the index of the element that is not equal to others.

Sample Input

4
4
11 13 11 11
5
1 4 4 4 4
10
3 3 3 3 10 3 3 3 3 3
3
20 20 10

Sample Onput

2
1
5
3

题目大意

给你 n ( n ≥ 3 ) n(n\geq3) n(n3)个数,其中只有一个数字与众不同。让你给出这个与众不同的数字下标。


解题思路

先看数据范围, t < 100 , n < 100 , a i < 100 t<100,n<100,a_i<100 t<100,n<100,ai<100,所以暴力就够了

一个很笨的方法就是输入数据之后,把每个数出现的次数+1,然后遍历一遍,得到出现一次的那个数。
再数组一遍数组,得到这个数的下标。


AC代码

#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int a[200];//记录题目中给的数组
int main()
{
    int N;
    cin>>N;
    while(N--)//N组测试样例
    {
        int n;
        cd(n);//scanf("%d", &n);
        int sum[200]={0};//记录出现的次数,sum[i]代表i出现的次数
        fi(i,0,200)//for(int i=0;i<200;i++)
            sum[i]=0;//初始值为0
        fi(i,0,n)
        {
            cd(a[i]);//输入a[i]
            sum[a[i]]++;//a[i]出现的次数++
        }
        int diff=0;//不同的那个数(只出现一次的那个数)
        fi(i,1,200)
        {
            if(sum[i]==1)//这个数只出现了一次
            {
                diff=i;
                break;
            }
        }
        // dbg(diff);
        fi(i,0,200)
        {
            if(a[i]==diff)//如果这个数就是只出现一次的那个数
            {
                printf("%d\n",i+1);//输出
                break;//结束循环
            }
        }
    }
    return 0;
}

原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/115592470

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tisfy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值