欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

"科林明伦杯"哈尔滨理工大学第八届程序设计竞赛(热身).Find numbers

程序员文章站 2022-06-01 10:26:04
...

Find numbers
Time Limit: 1000 MS Memory Limit: 256000 K
Total Submit: 5(5 users) Total Accepted: 5(5 users) Rating: "科林明伦杯"哈尔滨理工大学第八届程序设计竞赛(热身).Find numbers"科林明伦杯"哈尔滨理工大学第八届程序设计竞赛(热身).Find numbers"科林明伦杯"哈尔滨理工大学第八届程序设计竞赛(热身).Find numbers"科林明伦杯"哈尔滨理工大学第八届程序设计竞赛(热身).Find numbers Special Judge: No
Description

There are N Numbers here, you need find that pair of numbers they have the smallest absolute value. For example, 5 numbers -1, 2,-5,1,2. The pair of numbers meets the requirement is (2,2) because their absolute value is 0.

There are multiple cases, for each case, you just need output the smallest absolute value in one line.

Input

There are multiple cases, for each case, the first line is N(2<=N<=10000),the second line is N numbers and each number belongs to [-1000000,1000000].

Process to the end of file.

Output

For each case, output the answer with one line.

Sample Input

5

-1 2 -5 1 2

3

-1 -3 0

Sample Output

0

1

Hint

We all Participated in CSP.

考点:简单排序

#include<algorithm>
#include<iostream>
using namespace std;
const long long Maxn= 1e5+2;

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