반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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 29 30 31
Archives
Today
Total
05-19 00:03
관리 메뉴

ImJay

[파이썬/Python] 백준 6840번 Who is in the middle? 본문

Solved.ac - Python/Bronze V

[파이썬/Python] 백준 6840번 Who is in the middle?

ImJay 2023. 6. 5. 04:36
반응형

[파이썬/Python] 백준 6840번 Who is in the middle?

 

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


문제

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 anymore. The bowls can be sorted by weight with the lightest bowl being the Baby Bear’s bowl, the medium bowl being the Mama Bear’s bowl and the heaviest bowl being the Papa Bear’s bowl. Write a program that reads in three weights and prints out the weight of Mama Bear’s bowl. You may assume all weights are positive integers less than 100.

동화 '골디락스와 세 마리의 곰'에서 각 곰은 좋아하는 의자에 앉아 자신의 음식을 먹기 위해 각자 한 그릇의 죽을 가지고 있었습니다. 그러나 이야기에서는 골디락스가 그릇들을 테이블 위에서 이리저리 옮겨놓았기 때문에 그릇들이 올바른 의자에 있지 않았습니다. 그릇들은 무게 순으로 정렬될 수 있으며, 가장 가벼운 그릇은 Baby Bear(어린곰)의 그릇, 중간 무게의 그릇은 Mama Bear(엄마곰)의 그릇, 가장 무거운 그릇은 Papa Bear(아빠곰)의 그릇입니다. 세 개의 무게를 입력받고, Mama Bear의 그릇의 무게를 출력하는 프로그램을 작성하세요. 입력값은 모두 100 미만의 양의 정수라고 가정할 수 있습니다.

예제 입력

10
5
8

예제 출력

8

풀이

# 세 개의 무게를 입력
lst = [int(input()) for _ in range(3)]

# 무게를 정렬하고, 중간 무게에 해당하는 Mama Bear의 그릇의 무게를 출력
print(sorted(lst)[1])

이 프로그램은 입력값으로 세 개의 무게를 받아서 정렬 후 중간 무게를 출력하는 과정을 수행한다. 따라서 시간 복잡도는 입력값의 개수에 비례하며, 정렬 알고리즘에 의해 결정된다. 일반적으로 효율적인 정렬 알고리즘의 시간 복잡도는 O(n log n)이다. 이 경우, 입력값이 3개로 고정되어 있으므로 상수 시간이라고 볼 수 있다. 따라서 입력 크기에 상관없이 실행 시간이 일정하다.

반응형
Comments