코드로 우주평화

Total amount of points 본문

나는 이렇게 학습한다/Algorithm & SQL

Total amount of points

daco2020 2022. 4. 9. 20:40

Description:

Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the collection.

For example: ["3:1", "2:2", "0:1", ...]

Write a function that takes such collection and counts the points of our team in the championship. Rules for counting points for each match:

  • if x > y: 3 points
  • if x < y: 0 point
  • if x = y: 1 point

Notes:

  • there are 10 matches in the championship
  • 0 <= x <= 4
  • 0 <= y <= 4

 

 

Solution:

1. games 배열에 담긴 요소를 꺼내고 매치 점수를 비교한다.

2. x가 크다면 3점, x가 작다면 0점, x와 y가 동점이라면 1점을 더한다.

3. 다 더한 점수를 반환한다.

 

def points(games):
    return sum([{True:1,False:{True:3,False:0}[x>y]}[x==y] for x, _, y in games])

 

 

 

 

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Student's Final Grade  (0) 2022.04.11
Remove First and Last Character Part Two  (0) 2022.04.10
Transportation on vacation  (0) 2022.04.08
Beginner - Lost Without a Map  (0) 2022.04.07
Calculate average  (0) 2022.04.07