6/ 24 파이썬 공부
1. 백준 16727 ICPC
The Iranian ChamPions Cup (ICPC), the most prestigious football league in Iran, is reaching its end, and people are eagerly waiting for the finals, which happened to be between the two most popular Iranian teams, Persepolis and Esteghlal.
The ICPC finals consist of two matches, with each team competing as the home team in one match. The winning team is determined by aggregate score, the sum of the scores of the two matches. For example, if the scores of the two matches are Persepolis 6–0 Esteghlal in the first match, and Esteghlal 3–1 Persepolis in the second match, then the aggregate score will be Persepolis 7–3 Esteghlal, meaning that Persepolis is the winner. If aggregates are equal, the away goals rule is used to determine the winner, in which case the winner is the team that scored the most goals in the match it played away from home. If the result is still equal, a penalty shootout is required.
Hana, an avid football fan, is trying to figure out various scenarios in which her favorite team wins the finals. To this end, she aims to write a program that gets as input the number of goals in the two matches, and decides which team is the winner if it can be derived from the aggregate scores and the away goals rule, otherwise declares that the match goes to penalty kicks. You are going to help Hana write such a program.
The first line of the input contains two space-separated integers p1 and s1, where p1 and s1 are the number of goals scored by Persepolis and Esteghlal, respectively, in the first match in which Persepolis is the home team. The second line contains two space-separated integers s2 and p2, where s2 and p2 are the number of goals scored by Esteghlal and Persepolis, respectively, in the second match in which Esteghlal is the home team. All input integers are between 0 and 20, inclusively.
In the output, print the name of the winning team, either Persepolis or Esteghlal, if the winner can be determined by the aggregate scores and the away goals rule. Otherwise, print Penalty.
>>>해석
이란에서 가장 인기가 많은 축구 리그인 이란 챔피언스 컵(ICPC)도 끝을 향해 가고, 사람들은 이란에서 가장 유명한 두 팀인 페르세폴리스와 에스테그랄 간의 결승전을 열광적으로 기다리고 있습니다.
ICPC의 결승은 각 팀이 한 경기마다 홈 팀이 되어 총 두 경기로 진행됩니다.
우승팀은 두 경기에서 넣은 점수를 더한 합계 점수로 정해집니다.
예를 들어 두 경기의 점수가 첫 경기는 페르세폴리스 6 : 0 에스테그랄, 두번째 경기는 에스테그랄 3 : 1 페르세폴리스라면, 합계 점수는 페르세폴리스 7 : 3 에스테그랄이 되어 페르세폴리스가 우승팀이 됩니다.
합계 점수가 같다면 원정 다득점 규칙에 따라 우승자가 정해지는데, 이 말은 원정에서 더 많은 골을 넣은 팀이 우승팀이 된다는 뜻입니다.
축구 광팬인 한나는 그녀가 응원하는 팀이 우승하는 다양한 시나리오를 그려 보려 하고 있습니다. 이를 위해 그녀는 두 경기의 결과가 입력될 때, 합계 점수와 원정 다득점 규칙에 따라 우승자를 계산할 수 있는 경우 어느 팀이 우승자인지 판단하고, 그렇지 못할 경우 경기가 승부차기로 이어진다는 것을 알리는 프로그램을 작성하려 합니다. 한나가 이 프로그램을 작성할 수 있도록 도와줍시다.
입력의 첫 줄에는 공백으로 구분된 두 정수 p1, s1이 주어지는데, p1과 s1은 각각 페르세폴리스 홈에서 펼쳐지는 첫 경기에서 페르세폴리스와 에스테그랄이 득점한 골의 수입니다. 둘째 줄에도 공백으로 구분된 두 정수 s2, p2가 주어지는데, s2와 p2는 각각 에스테그랄 홈에서 펼쳐지는 두 번째 경기에서 에스테그랄과 페르세폴리스가 득점한 골의 수입니다. 입력되는 모든 정수는 0과 20을 포함한 그 사이 범위에 들어옵니다.
합계 점수와 원정 다득점 규칙에 따라 우승팀을 정할 수 있다면, 우승팀의 이름인 Persepolis 또는 Esteghlal을 출력합니다. 그렇지 않다면, Penalty를 출력합니다.
>>>코드
a, b = map(int, input().split())
c, d = map(int, input().split())
if a+d > b+c:
print('Persepolis')
elif a+d < b+c:
print('Esteghlal')
else:
if d > b:
print('Persepolis')
elif d < b:
print('Esteghlal')
else:
print('Penalty')
2. 백준 20233 Bicycle
After a long time at home during the quarantine, in November you decided to go to work by bicycle! Since you do not have your own bicycle, you have to rent one. The bike rental allows you to choose one of two monthly options:
The monthly fee is a roubles. Every day, the first 30 minutes are free, and every minute above that costs x roubles.
The monthly fee is b roubles. Every day, the first 45 minutes are free, and every minute above that costs y roubles.
There are 21 working days in November, and you spend T minutes commuting to work and back home in total every day. Calculate how many roubles you would spend if you use either one of two monthly options.
The first four lines of the input contain integers a, x, b, and y (0 <= a, x, b, y <= 100), each on a separate line. The last line contains a single integer T (1 <= T <= 1440) --- the total time spent on a bicycle during each day.
The only line of the output should contain two integers --- the amount of money you would spend on the first option and the second option, respectively.
>>>해석
집에서 긴 격리가 끝나고, 당신은 11월에 자전거로 출근을 하기로 다짐했습니다!
당신은 자전거가 없으므로, 하나를 빌려야 합니다.
자전거 대여 서비스는 한 달 기준 두 가지 옵션을 제공합니다:
- 월 요금은 a 루블입니다. 매일 첫 30분은 무료지만, 그 이후부터는 1분마다 x 루블이 부과됩니다.
- 월 요금은 b 루블입니다. 매일 첫 45분은 무료지만, 그 이후부터는 1분마다 y 루블이 부과됩니다.
11월에 일하는 날은 총 21일이고, 출퇴근에는 매일 총 T분이 걸립니다.
각 월 옵션을 이용할 경우 얼마만큼 루블을 내야 하는지 구합시다.
첫 네 줄에 각 줄마다 정수 a, x, b, y (0 <= a, x, b, y <= 100)가 주어집니다.
마지막 줄에는 매일 자전거에서 소비한 시간을 나타내는 T (1 <= T <= 1440)가 주어집니다.
딱 한 줄에 두 개의 정수를 출력합니다.
각각 첫 번째 옵션, 두 번째 옵션을 선택했을 때 지불해야 하는 금액의 양입니다.
>>>코드
a = int(input())
x = int(input())
b = int(input())
y = int(input())
n = int(input())
if n <= 30:
r1 = a
else:
r1 = a + (n-30)*x*21
if n <= 45:
r2 = b
else:
r2 = b + (n-45)*y*21
print(r1, r2)
3. 백준 13623 Zero or One
Everyone probably knows the game Zero or One (in some regions in Brazil also known as Two or One), used to determine a winner among three or more players. For those unfamiliar, the game works as follows. Each player chooses a value between zero or one; prompted by a command (usually one of the contestants announces “Zero or... One!”), all participants show the value chosen using a hand: if the value chosen is one, the contestant shows a hand with an extended index finger; if the value chosen is zero, the contestant shows a hand with all fingers closed. The winner is the one who has chosen a value different from all others. If there is no player with a value different from all others (e.g. all players choose zero, or some players choose zero and some players choose one), there is no winner.
Alice, Bob and Clara are great friends and play Zerinho all the time: to determine who will buy popcorn during the movie session, who will enter the swimming pool first, etc.. They play so much that they decided make a plugin to play Zerinho on Facebook. But since the don’t know how to program computers, they divided the tasks among friends who do know, including you.
Given the three values chosen by Alice, Bob and Clara, each value zero or one, write a program that determines if there is a winner, and in that case determines who is the winner.
The input contains a single line, with three integers A, B and C ,indicating respectively the values chosen by Alice, Beto and Clara.
Restrictions
A, B, C ∈ {0, 1}
Your program must output a single line, containing a single character. If Alice is the winner the character must be ‘A’, if Beto is the winner the character must be ‘B’, if Clara is the winner the character must be ‘C’, and if there is no winner the character must be ‘*’ (asterisc).
>>>해석
다들 셋 이상의 참가자 중 승자를 결정하는 0 또는 1 게임에 대해서는 아실 겁니다.
(브라질의 몇몇 지역에서는 2 또는 1로 알려져 있기도 합니다.)
모르시는 분들을 위해, 게임은 아래와 같이 진행됩니다.
각 참가자는 명령에 맞춰 0 또는 1 중 하나의 값을 고릅니다 (보통 한 명이 "0 또는... 1!"을 외칩니다.);
모든 참가자는 자신이 고른 값을 손을 이용해 나타냅니다:
만약 1을 골랐으면 참가자는 검지를 펼친 손을 내보이고, 0을 골랐다면 모든 손가락을 쥔 채 손을 내보입니다.
다른 모든 사람과 다른 값을 낸 한 명이 승자입니다.
만약 다른 모든 사람과 다른 값을 낸 참가자가 없다면 (예를 들어 모두 0을 골랐거나, 누구는 0을 고르고 누구는 1을 골랐을 경우) 승자는 없습니다.
친한 친구인 앨리스, 밥, 클라라는 항상 0 또는 1 게임을 합니다: 누가 영화 때 볼 팝콘을 살지, 누가 수영장에 먼저 들어갈지 별별 것을 다 가지고 말이죠. 게임을 너무 많이 한 나머지, 그들은 페이스북에 0 또는 1 게임을 할 수 있는 프로그램을 만들기로 했습니다. 하지만 어떻게 프로그램을 짤지 몰라, 당신을 포함해 알고 있는 친구들과 역할을 분담했습니다.
0 또는 1 중 앨리스, 밥, 클라라가 고른 세 개의 값이 주어질 때 승자가 있는지 없는지, 있다면 누가 승자인지 판단하는 프로그램을 작성합시다.
각각 앨리스, 밥, 클라라가 고른 값을 나타내는 세 정수 A, B, C가 한 줄에 입력됩니다.
제한
- A, B, C ∈ {0, 1}
한 줄에 문자 하나를 출력합니다. 앨리스가 승자일 경우 'A', 밥이 승자일 경우 'B', 클라라가 승자일 경우 'C', 승자가 없을 경우 '*' (별표)를 출력합니다.
>>>코드
l = list(map(int, input().split()))
if l[1] == l[2] and l[2] != l[0]:
print('A')
elif l[2] == l[0] and l[0] != l[1]:
print('B')
elif l[0] == l[1] and l[1] != l[2]:
print('C')
else:
print('*')'백준 > 백준 파이썬' 카테고리의 다른 글
| 백준 파이썬 Today I Learn 2023.06.26 (0) | 2023.06.30 |
|---|---|
| 백준 파이썬 Today I Learn 2023.06.25 (0) | 2023.06.30 |
| 백준 파이썬 Today I Learn 2023.06.23 (0) | 2023.06.30 |
| 백준 파이썬 Today I Learn 2023.06.22 (0) | 2023.06.29 |
| 백준 파이썬 Today I Learn 2023.06.21 (0) | 2023.06.28 |