문제: https://www.acmicpc.net/problem/2693
문제
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.
예제 입력
4 1 2 3 4 5 6 7 8 9 1000 338 304 619 95 343 496 489 116 98 127 931 240 986 894 826 640 965 833 136 138 940 955 364 188 133 254 501 122 768 408
예제 출력
8 489 931 768
힌트
출처
ACM-ICPC > Regionals > North America > Greater New York Region > 2009 Greater New York Programming Contest A번
- 문제를 번역한 사람: baekjoon
간단하게 라이브러리의 quick sort 을 사용해서...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <fstream> #include <iostream> #include <cstring> #include <climits> #include <algorithm> using namespace std; int compare(const void * a, const void * b) { return (*(int*)a - *(int*)b); } int main() { int cases; cin >> cases; for (int i = 0; i < cases; i++) { int arr[10] = { 0, }; for (int j = 0; j < 10; j++) cin >> arr[j]; qsort(arr, 10, sizeof(int), compare); cout << arr[7] << endl; } return 0; } | cs |
'Algorithm, Data structure > Solved Algorithmic Problem' 카테고리의 다른 글
BAEKJOON 2696 - Running Median (0) | 2016.12.13 |
---|---|
BAEKJOON 2694 - Equal Sum Partitions (0) | 2016.12.12 |
BAEKJOON 2699 - Convex Hull of Lattice Points (0) | 2016.12.11 |
BAEKJOON 2688 - Non-Decreasing Digits (0) | 2016.12.09 |
BAEKJOON 2685 - Nim-B Sum (0) | 2016.12.07 |