EOJ(排序)——4. Nth Largest Value
4. Nth Largest Value
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.
输入
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.
输出
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.
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
output
1 8
2 489
3 931
4 768
题目大意:
输入 p行,每行10个元素,求出每一行的第三大的数。
题目解析:
用数组存储每一行的数据,用sort函数完成排序。(注意:数据的输入输出标有行号)
具体代码:
#include<iostream> #include<algorithm> using namespace std; bool cmp(int a,int b){ return a>b; } int main() { int n; int A[11]; cin>>n; for(int i=1;i<=n;i++){ fill(A,A+11,0); for(int j=0;j<11;j++) cin>>A[j]; sort(A+1,A+11,cmp); cout<<i<<" "<<A[3]<<endl; } return 0; }
- EOJ(排序)——2015. 自修室
- EOJ——Problem #3291——素数个数排序
- EOJ 2844 排序去重
- EOJ(排序)——2031. 绝对值排序
- EOJ(排序)——2572. Sort it…
- EOJ 2844. 排序去重
- EOJ 3292 解密字符串(排序)
- EOJ 1806 选择排序
- EOJ 3124 单词表(排序)
- [EOJ][ECNU]Problem2896. 随机排序
- EOJ(排序)——2844. 排序去重
- EOJ 3239 最长的等差数列(排序+枚举)
- EOJ(排序)——2849. 成绩排序
- EOJ 3236 字串非重复字符数排序
- EOJ(排序)——97. 邮件地址排序
- EOJ(排序)——1072. 小强的单词本
- EOJ(排序)——2878. 字串排序
- EOJ(排序)——1182. Relative Relatives
- EOJ(排序)——2945. Search Web Pages
- EOJ(排序)——1852. Ordered Fractions