HDU-2561 second smallest integer

Description

Find the penultimate smallest number of n integers.
Each integer is regarded as a number independently, for example, there are three numbers are 1, 1, 3, then, the second smallest number is 1.

Input

The input contains multiple sets of test data.
The first line of input is an integer C, indicating that there is C test data;
the first line of each set of test data is an integer n, indicating that the test data of this group has n integers (2 <= n <= 10), followed by a line Is n integers (each number is less than 100);

Output

Please output the second smallest integer for each set of test data, each set of output occupies one line.

Sample Input

2
2
1 2
3
1 1 3

Sample Output

2
1
#include <stdio.h>

int a[105];

int main()
{
    int n, m;
    int temp, t;
    
    scanf("%d", &n);
    while (n--){
        scanf("%d", &m);
        for (int i = 0; i < m; i++)
            scanf("%d", &a[i]);
        for (int i = 0; i < 2; i++){
            t = i;
            for (int j = i + 1; j < m; j++)
                if (a[j] <= a[t])
                    t = j;
            temp = a[t];
            a[t] = a[i];
            a[i] = temp;
        }
        printf("%d\n", a[1]);
    }
    return 0;
}

 

Published 339 original articles · praised 351 · 170,000 views

Guess you like

Origin blog.csdn.net/Aibiabcheng/article/details/105353591