Daily AtCoder # 4 in Python

Introduction

Last time It's the 4th day.

#4 Problem Hooray. B problem

** Thoughts ** Sort the entered [City Name, Population] by population to determine if there is a majority of the largest towns. In my case, it's a two-dimensional array like [town name, population], so I can't sort normally, so

s.sort(key=lambda x: int(x[1]),reverse=True)

Sorted in. Reference page I like it because it's fashionable and cool. You can sort by specifying the index of the element with x: int (x [n]). This time, I want to sort by population, so x [1], and I want to sort by population, so reverse = True.

Population was calculated with the for statement.

population = 0
for i in range(n):
    population += int(s[i][1])

I wrote the variable name properly in an easy-to-understand manner. It's a little long though. All you have to do is put it in the if statement.

n = int(input())
s = [list(input().split()) for _ in range(n)]

population = 0
for i in range(n):
    population += int(s[i][1])

s.sort(key=lambda x: int(x[1]),reverse=True)

if int(s[0][1]) > population//2:
    print(s[0][0])
else:
    print('atcoder')

Finally, be careful of misspellings in print ('atcoder').

Summary

I think that even the B problem is easy. I'm wondering whether to post tomorrow because there is a contest. ~~ Post every day ~~ see you

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
atCoder 173 Python
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
[Python] Basic knowledge used in AtCoder
Quadtree in Python --2
Python in optimization