Easy Task

You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these n integers. And then you should replace both a and bwith a-b. Your task will not be finished unless all the integers are equal.

Now the problem come, you want to know whether you can finish you task. And if you can finish the task, you want to know the final result.

Input

The first line of the input contain an integer T(T≤ 20) indicates the number of test cases.

Then T cases come. Each case consists of two lines. The first line is an integer n(2≤ n≤ 10) as the problem described. The second line contains n integers, all of them are no less than -100000 and no more than 100000.

Output

For each case you should print one line. If you can finish your task, you should print one of the n integers. Otherwise, you should print "Nooooooo!"(without quotes).

Sample Input
2
3
1 2 3
2
5 5
Sample Output
2
5

 

//最大值与最小值相减,使最后所有数都相等。
//循坏排序得出两端的最大值与最小值,相减。

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
  int t,n,sum;
  int a[12],i;
  while(scanf("%d",&t)!=EOF)
  {
    while(t--)
    {
    scanf("%d",&n);
    for(i=0;i<n;i++)
      scanf("%d",a+i);
      
    while(1)
    {
      sort(a,a+n);
      if(a[n-1]==a[0]) break;//最大值与最小值相等,则所有数都相等。
      sum=a[n-1]-a[0];
      a[n-1]=a[0]=sum;
    }                 
     printf("%d\n",a[n-1]);      
  }   
}
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值