반응형
문제
6840번: Who is in the middle? (acmicpc.net)
6840번: Who is in the middle?
In the story Goldilocks and the Three Bears, each bear had a bowl of porridge to eat while sitting at his/her favourite chair. What the story didn’t tell us is that Goldilocks moved the bowls around on the table, so the bowls were not at the right seats
www.acmicpc.net
풀이
단순 값 비교 문제입니다. 세 개의 숫자가 들어오고, 그 중에서 두번째로 큰 수를 출력하면 됩니다.
#include <iostream>
using namespace std;
int main() {
int A, B, C;
cin >> A;
cin >> B;
cin >> C;
int middle;
middle = (A >= B && A <= C) ? A :
(B >= A && B <= C) ? B :
(C >= A && C <= B) ? C :
(A >= C && A <= B) ? A :
(B >= C && A >= C) ? B : C;
cout << middle;
return 0;
}
반응형
'📊 알고리즘' 카테고리의 다른 글
[백준] 14337 - Helicopter (0) | 2022.12.26 |
---|---|
[백준] 26489 - Gum Gum for Jay Jay (0) | 2022.12.25 |
[백준] 10189 - Hook (0) | 2022.12.23 |
[백준] 2547 - 사탕 선생 고창영 (0) | 2022.12.23 |
[백준] 2377 - Pottery (0) | 2022.12.22 |