ZOJ :: 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 <algorithm>
using namespace std; 

#define MAX 11

int t,n; 
int a[MAX]; 

int main()
{
	cin>>t; 
	int mid; 
	while (t--)
	{
		cin>>n;   
		for (int i=0;i<n;i++){
			cin>>a[i]; 
		}
		while(1){  
			sort(a,a+n);  
			if(a[0]==a[n-1]) break; 
			mid=a[n-1]-a[0]; 
			a[n-1]=a[0]=mid;  
		}
		cout<<a[0]<<endl; 
	} 
	return 0; 
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章