Nth Largest Value
2024-09-30 22:29:45
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 ;
}
最新文章
- jqueryAjax在客户端发送请求的方式
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 基于数据库资源的多语言实现
- Mac +WebStorm+nodeJs+Freemarker.js的安装与使用
- AccessHelper 需修改
- Scau 8633 回文划分 mancher + dp
- 关于oracle-12514错误的修改方法
- MySQL 索引、视图、DML
- 每天一个JS 小demo之个人信息添加。主要知识点:DOM操作中的表格操作,节点操作
- Matplotlib初体验
- 一次saltstack环境变量的坑
- C++-int类型整数超出范围后的处理
- burp抓取手机模拟器流量
- 分布式文件系统(HDFS)与 linux系统文件系统 对比
- python的MD5
- js_计时器之setInterval
- 存储过程DT参数
- JAVA多线程Thread VS Runnable详解
- j.u.c系列(07)---之读写锁:ReentrantReadWriteLock
- 转-spring boot web相关配置
- Mysql replace into
热门文章
- (DP)51NOD 1049 最大子段和
- 洛谷 P1462 通往奥格瑞玛的道路(spfa+二分搜索)(4boy)
- [Qt Creator 快速入门] 第8章 界面外观
- Android 性能优化(22)*性能工具之「Hierarchy Viewer」 Hierarchy Viewer Walkthrough
- LN : leetcode 241 Different Ways to Add Parentheses
- css的新特性 calc () 使用
- setTimeout 0
- 3星|林毅夫《战胜命运》:事实证明华盛顿共识是错误的,GIFF是穷国发展正道。
- c3p0参数详解
- HDU_1874_畅通工程续_最短路问题