문제 자체는 간단한 구현 문제이다.
이 문제를 푸는 방법은 채점 현황에 따른 다양한 사람들의 풀이를 보니 (특히 시간이 나보다 빠른 사람들 것을 보았다), 특별히 눈에 띄었던 것을 배열을 사용하는 것이다.
이런 문제에서 배열사용하는 것 또한 내가 가장 좋아하는 방법인데, 파이썬을 사용하게 되면서 배열을 잘 사용하지 못하게 된 느낌이 든다.
따라서 내가 푼 방법과 배열을 활용하여 푼 방법을 정리해둔다.
내가 푼 코드:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
apple_total = 0
banana_total = 0
for score in [3, 2, 1]:
apples = int(input())
apple_total = apple_total + score*apples
for score in [3, 2, 1]:
bananas = int(input())
banana_total = banana_total + score*bananas
if apple_total > banana_total:
print('A')
elif apple_total < banana_total:
print('B')
else:
print('T')
|
cs |
다음은 배열형태로해서 append를 통해 푼 코드:
1
2
3
4
5
6
7
8
9
|
arr=[]
for i in range(6):
arr.append(int(input()))
d1 = arr[0]*3 + arr[1]*2 + arr[2]
d2 = arr[3]*3 + arr[4]*2 + arr[5]
s = "T"
if d1 > d2 : s = "A"
elif d1 < d2 : s = "B"
print(s)
|
cs |
출처: https://www.acmicpc.net/problem/17009
17009번: Winning Score
The first three lines of input describe the scoring of the Apples, and the next three lines of input describe the scoring of the Bananas. For each team, the first line contains the number of successful 3-point shots, the second line contains the number of
www.acmicpc.net
'코딩 문제풀이 및 연습 > Python 연습' 카테고리의 다른 글
[백준]17094_Serious Problem 파이썬 (계속 오류 나서 시간이 좀 걸렸던 문제...) (0) | 2021.07.18 |
---|---|
[백준] 17010_Time to Decompress 파이썬 (str과 int를 space로 나눠서 동시에 입력받기) (0) | 2021.07.17 |
[백준]16170_오늘의 날짜는 파이썬 (datetime, timedelta, year, month, day) (0) | 2021.07.17 |
[백준] 17388_와글와글 숭고한 파이썬 (0) | 2021.07.17 |
[백준]2920_음계 파이썬 파이썬 (정렬과 copy활용) (0) | 2021.07.16 |