[HackerRank][Python3] Jim and the Orders
2018. 9. 8. 22:40 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/jim-and-the-orders/problem
My Solution :
#!/usr/bin/env python3
def jim_orders(orders):
result = [(i, sum(times)) for i, times in enumerate(orders, start=1)]
result = sorted(result, key=lambda x: x[1])
result = [str(x[0]) for x in result]
return ' '.join(result)
n = int(input())
orders = []
for _ in range(n):
orders.append(list(map(int, input().rstrip().split())))
result = jim_orders(orders)
print(result)
Comment :
위 방법은 파이썬의 list comprehension과 lambda 함수를 적절히 활용해본 것이고, 아래 방법은 dictionary를 활용해본 것이다.
My Solution2 :
#!/usr/bin/env python3
def jim_orders(orders):
times = {}
for i, time in enumerate(orders, start=1):
times.setdefault(sum(time), []).append(i)
for time, indexes in sorted(times.items()):
for index in indexes:
yield index
n = int(input())
orders = []
for _ in range(n):
orders.append(list(map(int, input().rstrip().split())))
result = jim_orders(orders)
print(' '.join(map(str, result)))
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Game of Stones (0) | 2018.09.09 |
---|---|
[HackerRank][Python3] Sum vs XOR (0) | 2018.09.09 |
[HackerRank][Python3] Maximizing XOR (0) | 2018.09.08 |
[HackerRank][Python3] Permuting Two Arrays (0) | 2018.09.08 |
[HackerRank][Python3] Largest Permutation (0) | 2018.09.08 |
[HackerRank][Python3] Priyanka and Toys (0) | 2018.09.08 |
[HackerRank][Python3] Beautiful Pairs (0) | 2018.09.08 |
[HackerRank][Python3] Maximum Perimeter Triangle (0) | 2018.09.08 |
최근에 달린 댓글 최근에 달린 댓글