HDU 2561 第二小整數(水題)

第二小整數

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12781 Accepted Submission(s): 7725

Problem Description
求n個整數中倒數第二小的數。
每一個整數都獨立看成一個數,比如,有三個數分別是1,1,3,那麼,第二小的數就是1。

Input
輸入包含多組測試數據。
輸入的第一行是一個整數C,表示有C測試數據;
每組測試數據的第一行是一個整數n,表示本組測試數據有n個整數(2<=n<=10),接着一行是 n個整數 (每個數均小於100);

Output
請爲每組測試數據輸出第二小的整數,每組輸出佔一行。

Sample Input
2
2
1 2
3
1 1 3

Sample Output
2
1

code:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main()
{
    int N;
    scanf("%d",&N);
    while (N--)
    {
        int n;
        scanf ("%d",&n);
        int a[1003];
        for (int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        printf ("%d\n",a[1]);

    }
}
發佈了268 篇原創文章 · 獲贊 296 · 訪問量 27萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章