Time Limit: 2 Seconds Memory Limit: 65536 KB
题目:
You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these nintegers. And then you should replace both a and b with 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 Output2
5
难度:签到题
说一下我的思路吧:
超简单的一道题,,,但是做题的时候虽然有算过一些数值组合,一直没有输出Nooooooo,然后我就想能不能有一些特殊值没有想到,然后就没有上交,,,然后我就想的有点多了,这道题,只需要将输入的数字排序,然后用最后一个数值-第一个数值,再把两个数值替换为这个差值,比较者这些数字是否相等,若相等,则输出这些数字中的相同的数字。(不存在输出Nooooooo的情况)。一下就是我的代码。
代码:
#include <bits/stdc++.h>
using namespace std;
int n;
int a[15];
bool equall()
{
for(int i=1;i<n;i++)
{
if(a[i]!=a[i-1])
{
return true;
}
}
return false;
}
int main()
{
int t;
cin>>t;
int max_,min_,m;
while(t--)
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
max_=a[n-1];
min_=a[0];
while(equall())
{
sort(a,a+n);
max_=a[n-1];
min_=a[0];
m=max_-min_;
a[n-1]=m;
a[0]=m;
}
cout<<a[0]<<endl;
}
return 0;
}