求第N数大问题
问题:
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
回答:题意输出10个数,求里面第3大数问题。如"1 2 3 4 5 6 7 8 9 1000"里面数值排第三是8。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int T;
for(scanf("%d",&T);T;T--)
{
int ca,a[12];
scanf("%d",&ca);
for(int i=0;i<10;i++)
scanf("%d",a+i);
sort(a,a+10);
printf("%d %d\n",ca,a[7]);
}
return 0;
}
求第N数大问题的更多相关文章
- 评playerc网友的"求比指定数大且最小的“不重复数”问题"
问题见:对Alexia(minmin)网友代码的评论及对“求比指定数大且最小的‘不重复数’问题”代码的改进 .算法:求比指定数大且最小的“不重复数”问题的高效实现 . playerc网友的代码如下(求 ...
- 对Alexia(minmin)网友代码的评论及对“求比指定数大且最小的‘不重复数’问题”代码的改进
应Alexia(minmin)网友之邀,到她的博客上看了一下她的关于“求比指定数大且最小的‘不重复数’问题”的代码(百度2014研发类校园招聘笔试题解答),并在评论中粗略地发表了点意见. 由于感觉有些 ...
- sum_series() 求一列数的指定个数的数和(5个数字的和)
#include <stdio.h> #include <stdarg.h> /*用sum_series() 求一列数的指定个数的数和(5个数字的和)*/ double sum ...
- 分页过滤SQL求总条数SQL正则
public static void main(String[] args) throws Exception { String queryForScanUsers_SQL = "selec ...
- H面试程序(29):求最大递增数
要求:求最大递增数 如:1231123451 输出12345 #include<stdio.h> #include<assert.h> void find(char *s) { ...
- codeforces 429 On the Bench dp+排列组合 限制相邻元素,求合法序列数。
限制相邻元素,求合法序列数. /** 题目:On the Bench 链接:http://codeforces.com/problemset/problem/840/C 题意:求相邻的元素相乘不为平方 ...
- P1474 货币系统 Money Systems(完全背包求填充方案数)
题目链接:https://www.luogu.org/problemnew/show/1474 题目大意:有V种货币,求用V种货币凑出面值N有多少种方案. 解题思路:就是完全背包问题,只是将求最大价值 ...
- HDU 1171 Big Event in HDU【01背包/求两堆数分别求和以后的差最小】
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 【C语言】不使用大小于号,求出两数最大值
//不使用大小于号,求出两数最大值 #include <stdio.h> #include <math.h> double Max(double a, double b) { ...
随机推荐
- PHP 运行方式(PHP SAPI介绍)
SAPI:Server Application Programming Interface 服务器端应用编程端口.它就是PHP与其它应用交互的接口,PHP脚本要执行有很多种方式,通过Web服务器,或者 ...
- f2fs解析(十)nid 如何从nat_root中删除
上面我们谈到了一个nid如何从free_nid中转移到node_info中去[分别有一个链表和一棵基数树搭伙做事],讲free_nid时,详细说明了free_nid中是如何进如何出的,上一篇说了nid ...
- Dungeon Game ——动态规划
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- C语言 二级指针内存模型②
//二级指针第二种内存模型 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #incl ...
- SQL语句的添加、删除、修改多种方法
SQL语句的添加.删除.修改虽然有如下很多种方法,但在使用过程中还是不够用,不知是否有高手把更多灵活的使用方法贡献出来? 添加.删除.修改使用db.Execute(Sql)命令执行操作╔------- ...
- [MySQL] 按日期进行统计(前一天、本周、某一天)
在mysql数据库中,常常会遇到统计当天的内容.例如,在user表中,日期字段为:log_time统计当天 sql语句为: select * from user where date(log_time ...
- 20145215《Java程序设计》课程总结
20145215<Java程序设计>课程总结 每周读书笔记链接汇总 20145215<Java程序设计>第一周学习总结 20145215<Java程序设计>第二周学 ...
- 关于php析构函数的一个有趣问题
随着面向对象编程的普遍展开,面向对象展现了其中很多有趣的问题.相信很多初学者学习php面向对象时会接触两个函数,构造函数与析构函数.构造函数似乎用的更多,析构函数用的较少(相对初学者有限编程经验而言, ...
- 使用git提交本地代码到github
1. 客户端选择 git在本地,有多种客户端可供选择,比如eclipse的插件EGit,还有git的官方客户端: Git Bash, Git CMD, Git GUI等. 推荐使用官方的Git Ba ...
- 全解┃OpenStack Newton发布,23家中国企业上榜(转载)
(转载自Openstack中文社区) 陈, 翔 2016-10-8 | 暂无评论 美国奥斯汀时间10月6日(北京时间6日24点),OpenStack Newton版本正式发布,在可扩展性.可靠性和用户 ...