728x90
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
문제 풀이
3개의 입력값을 리스트에 받아준 뒤, 정렬 후 중간 값을 출력해주면 된다.
정답 코드
C++
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define ll long long
int main() {
fast;
int n;
vector<int> v;
for (int i = 0; i < 3; i++) {
cin >> n;
v.push_back(n);
}
sort(v.begin(), v.end());
cout << v[1];
}
python
lst = []
for _ in range(3) : lst.append(int(input()))
lst.sort()
print(lst[1])
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 6887 - Squares [C++/python] (0) | 2023.03.02 |
---|---|
[BOJ/백준] 6841 - I Speak TXTMSG [C++/python] (0) | 2023.03.02 |
[BOJ/백준] 6825 - Body Mass Index [C++/python] (0) | 2023.03.02 |
[BOJ/백준] 5524 - 입실 관리 [C++/python] (0) | 2023.03.02 |
[BOJ/백준] 5358 - Football Team [C++/python] (0) | 2023.03.02 |