HDU 2561 第二小整数(排序,水)

第二小整数

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


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
 

 

Author
yifenfei
 

 

Source
 

 

Recommend
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
   int t;
   int n;
   int a[105];
   scanf("%d",&t);
   while(t--)
   {
       scanf("%d",&n);
       for(int i=0;i<n;i++)
       {
           scanf("%d",&a[i]);
       }
       sort(a,a+n);//在for循环外面!!!
       printf("%d\n",a[1]);
   }
}

  

 
posted @ 2017-07-19 17:49  Roni_i  阅读(176)  评论(0编辑  收藏  举报