Problem Description
For this problem, you will write a program that prints the Nth largest value in a fixed sized array of integers. To make things simple, N will be 3 and the array will always be have 10 decimal integer values.
 
Input
The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set consists of a single line containing the data set number, followed by a space,followed by 10 space separated decimal integers whose values are between 1 and 1000 inclusive.
 
Output
For each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the 3rd largest value of the corresponding 10 integers.
 
Sample Input
4
1 1 2 3 4 5 6 7 8 9 1000
2 338 304 619 95 343 496 489 116 98 127
3 931 240 986 894 826 640 965 833 136 138
4 940 955 364 188 133 254 501 122 768 408
 
Sample Output
1 8
2 489
3 931
4 768
 
 #include <stdio.h> 

 int main(){
int T;
int n;
int number;
int i;
int max;
int middle;
int min; scanf("%d",&T); while(T--){
max=; //对最大的三个数进行初始化
middle=;
min=;
scanf("%d",&n); for(i=;i<;i++){
scanf("%d",&number); if(number>max){ //如果找到当前最大的数,舍去最小数
min=middle;
middle=max;
max=number;
} else if(number>middle){ //如果找到当前第二大的数,舍去最小数
min=middle;
middle=number;
} else if(number>min) //如果找到当前第三大的数,舍去最小数
min=number;
} printf("%d %d\n",n,min); }
return ;
}

Nth Largest Value的更多相关文章

  1. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  2. STL algorithm源代码:stl_algo.h

    <span style="font-size:18px;">// Algorithm implementation -*- C++ -*- // Copyright ( ...

  3. c++ stl nth_element 原理解析

    nth_element是stl中的一个库函数,它会使迭代器nth所指的元素与整个[first,last)完整排序后.同一个位置的元素同值.即找到完整排序时第n位的正确值. 但这个函数与完整排序的区别在 ...

  4. ural 1218. Episode N-th: The Jedi Tournament

    1218. Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Je ...

  5. URAL 1218 Episode N-th: The Jedi Tournament(强连通分量)(缩点)

    Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Jedi Kni ...

  6. Lettcode Kth Largest Element in an Array

    Lettcode Kth Largest Element in an Array 题意:在无序数组中,寻找第k大的数字,注意这里考虑是重复的. 一直只会简单的O(nlogn)的做法,听说这题有O(n) ...

  7. CSS3 nth 伪类选择器

    考察下面的 HTML 代码片段: <div> <section>section 1</section> <section>section 2</s ...

  8. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  9. [LeetCode] Split Array Largest Sum 分割数组的最大值

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

随机推荐

  1. 微信小程序setData的使用,通过[...]进行动态key赋值

    首先先介绍一下微信小程序Page.prototype.setData(Object data, Function callback)的讲解: setData函数用于将数据从逻辑层发送到视图层(异步), ...

  2. JS 实现PDF文件打印

    function PdfPrint() {        bdhtml = window.document.body.innerHTML;        sprnstr = "<!-- ...

  3. 【洛谷2617_BZOJ1901】Dynamic Rankings(树套树)

    题目: 洛谷 2617 BZOJ 1901 是权限题,\(n=10^4\) ,内存 128 MB :洛谷 2617 \(n=10^5\) ,内存 1024 MB ,数据比较坑. 分析: 蒟蒻初学树套树 ...

  4. hdu6198 number number number(递推公式黑科技)

    number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. spring的依赖注入如何降低了耦合

    依赖注入:程序运行过程中,如需另一个对象协作(调用它的方法.访问他的属性时),无须在代码中创建被调用者,而是依赖于外部容器的注入 看过一些比较好的回答 1.一个人(Java实例,调用者)需要一把斧子( ...

  6. OpenCV2.4.9 + VS2012 + win10 配置

    Step1 下载opencv 2.4.9 pack Step2 解压到本地 我解压路径是: C:\OPENCV Step3 添加环境变量: 这里虽然把X64下的VC11(VC11对应VS2012的C+ ...

  7. Linux 介绍快速浏览

    Linux 介绍 内核 库: .so 共享对象,windows:dll 动态链接库 应用程序 Linux的基本原则:1.由目的单一的小程序组成:组合小程序完成复杂任务:2.一切皆文件:3.尽量避免捕获 ...

  8. GDB 使用小结

    GDB 使用小结 Gdb 不用说,两个字,非常强大 >.<,我最讨厌不识数的人了 本文适合GDB 初学和没学过的,如果你懂了,可以相互交流 既然说它很强大,它强大在哪里呢? 一般情况下,大 ...

  9. Java&Xml教程(八)使用JDOM将Java对象转换为XML

    在前面的教程中我们学习了如何使用JDOM解析和修改XML文件内容,本节介绍如何将Java对象转换为XML数据并生成文件. JDOM的Document类提供了便捷的方法创建元素和属性,XMLOutput ...

  10. HDU_2476_String painter_(区间dp)

    String painter Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...