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. java 并发编程 Executor框架

    http://blog.csdn.net/chenchaofuck1/article/details/51606224 demo package executor; import java.util. ...

  3. Asp.NET 知识点总结(二)

    1.两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对? 答:不对,有相同的 hash code 编码格式. 2.swtich是否能作用在byte ...

  4. 391 Perfect Rectangle 完美矩形

    有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域.每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1,2,2]. ( ...

  5. Linux学习日记之crontab使用notify-send实现每小时通知提醒

    crontab命令用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行 通过crontab -e 可以打开编辑文件添加新的命令 notif ...

  6. Android基础TOP5_1:AutoCompleteTextView自动补全文本框

    1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  7. axios 正确打开方式

    一.安装1. 利用npm安装npm install axios --save2. 利用bower安装bower install axios --save3. 直接利用cdn引入<script s ...

  8. [转]最值得拥有的免费Bootstrap后台管理模板

    在PHP开发项目中,后台管理因为面向群体相对比较固定,大部分以实现业务逻辑和功能.使用Bootstrap后台模板可以让后端开发很轻松的就展现给客户一个响应式的后台,节约前端开发的时间.下面PHP程序员 ...

  9. BZOJ 3884: 上帝与集合的正确用法 扩展欧拉定理 + 快速幂

    Code: #include<bits/stdc++.h> #define maxn 10000004 #define ll long long using namespace std; ...

  10. 扩增子分析QIIME2-3数据导出Exporting data

    # 激活工作环境 source activate qiime2-2017.8 # 建立工作目录 mkdir -p qiime2-exporting-tutorial cd qiime2-exporti ...