22A

来源:互联网 发布:淘宝守望先锋代练 编辑:程序博客网 时间:2024/05/22 08:00

A. Second Order Statistics
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.

Input

The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.

Output

If the given sequence has the second order statistics, output this order statistics, otherwise output NO.

Examples
input
41 2 2 -4
output
1
input
51 2 3 1 1
output
2

题意:让我们求第二小的那个数,然后输出,没有就输出NO、

题解:,由于数据很小暴力,排序后输出当前不等于前一个的术,就是的第二小的。eg:111233 ,2第一个不等于前面,第二小,输出2。

#include<bits/stdc++.h>using namespace std;int main(){    int a[110],n;    while(cin>>n)    {        for(int i=0;i<n;i++)            cin>>a[i];        sort(a,a+n);        for(int i=1;i<n;i++)        {            if(a[i]!=a[i-1])            {                cout<<a[i]<<endl;                return 0;            }        }        puts("NO");    }    return 0;}


原创粉丝点击