The Nearest Same Chocolate

来源:互联网 发布:软件社群 编辑:程序博客网 时间:2024/05/17 20:30

Description

    Now it is well-known that after the 40th ACM/ICPC, Diao Yang has found many girlfriends, and Diao Yang will buy much candies for them every day. But today, Diao Yang has no much money to buy any candies for his girlfriends. Because Diao Yang is always very nice to his girlfriends, these pretty girls decided to buy some chocolates for him today as return.

    Then Girls went to a supermarket and chose many different chocolates. In order to distinguish these chocolates, they marked them by numbers. Any two chocolates chosen by the same girl were marked by the same number, and any two chocolates chosen by different girls were marked by different numbers. Then girls went back home, put their chocolates in a line on the table and gave Diao Yang to eat. But before Diao Yang ate, the girls gave him a problem: can you find the distance of the nearest two chocolates which were marked by the same girl? As Diao Yang is too hungry to solve this problem, he asks you for help.

Input

    The first line contains an integer T indicating the total number of test cases.

    In each test case, there are two lines. The first line is an integer n(), indicating there are  chocolates. The second line contains n integers, indicating the marked number for each chocolate. All the integers will be no more than 100.

Output

    For each test case, output the answer in one line. You can assume that there are at least two chocolates which were marked by the same girl.

Sample Input


282 3 8 1 5 3 4 562 3 2 1 3 1

Sample Output

32
这题就是让找相同的数的最小距离
#include<stdio.h>
int main()
{
int t,n,i=0,j=0,m=0;
int min=200;
int a[105];
scanf("%d",&t);
while(t--)
{
min=200;//此处忘了,导致一直WA,当多组数据时要赋值新的新值。
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
if(a[i]==a[j])
{
m=j-i;
if(min>m)
min=m;
}
}
if(min==200)
printf("%d\n",0);
else
printf("%d\n",min);
}
return 0;
}
0 0