AtCoder ABC171 This is a summary of the problems of AtCoder Beginner Contest 171 held on 2020-06-21 (Sun) in order from problem A, taking into consideration the consideration. The first half deals with problems up to ABC. The problem is quoted, but please check the contest page for details. Click here for the contest page Official commentary PDF
Problem statement Either uppercase or lowercase $ 1 $ characters $ α $ are entered. Output "A" if $ α $ is uppercase, or "a" if it is lowercase.
There are many ways to determine whether it is uppercase or lowercase, but this time I used `str.istitle ()`
.
abc171a.py
n = input()
if n.istitle():
print("A")
else:
print("a")
Problem statement A store sells $ N $ varieties of fruits, fruits $ 1,…, N $, each priced at $ p_1,…, p_N $ yen. When buying $ K $ fruit varieties one by one at this store, ask for the lowest possible total price for them.
You can buy $ k $ kind of fruit from the cheapest one, so you can easily solve it by sorting the price.
abc171b.py
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
p_list = sorted(p_list)
print(sum(p_list[:k]))
Problem statement Roger decided to keep all the $ 1000000000000001 $ dogs that suddenly appeared to him. The dogs were originally numbered from $ 1 $ to $ 1000000000000001 $, but Roger gave them names according to the following rules: ・ Dogs numbered $ 1,2, ⋯, 26 $ are named a, b, ..., z in that order. ・ Dogs numbered $ 27,28,29, ⋯, 701,702 $ are named aa, ab, ac, ..., zy, zz in that order. ・ The dogs numbered $ 703,704,705, ⋯, 18277,18278 $ are named aaa, aab, aac, ..., zzy, zzz in that order. ・ The dogs numbered $ 18279,18280,18281, ⋯, 475253,475254 $ are named aaaa, aab, aaaac, ..., zzzy, zzzz in that order. ・ $ 475255,475256, ⋯ Dogs with $ numbers are named aaaaa, aaaab, ... in that order. ・ (Omitted below) In other words, if you sort the names given by Roger in numerical order: a, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab ,. .., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ... Roger has caused you a problem. "Answer the name of the dog with the number $ N $."
I thought that it could be solved with a 26-ary idea, so I implemented it and it passed.
abc171c.py
n = int(input())
n = n - 1
mozi_list = []
while True:
k = n % 26
n = n // 26 - 1
chr_s = chr(97 + k)
mozi_list.append(chr_s)
if n == -1:
break
for i in range(len(mozi_list)):
print(mozi_list[len(mozi_list)-i-1], end="")
This is the end of the first half. This time, the explanation was written very carefully, so I hope you can refer to that for the detailed solution. Thank you for reading to the end of the first half.
The second half will explain the DEF problem. Continued in the second half.
Recommended Posts