[PYTHON] AtCoderBeginnerContest171 Review & Summary (first half)

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 A αlphabet

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 B Mix Juice

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]))

C problem One Quadrillion and One Dalmatians

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

AtCoderBeginnerContest175 Review & Summary (first half)
AtCoderBeginnerContest169 Review & Summary (first half)
AtCoderBeginnerContest174 Review & Summary (first half)
AtCoderBeginnerContest173 Review & Summary (First Half)
AtCoderBeginnerContest165 Review & Summary (first half)
AtCoderBeginnerContest170 Review & Summary (first half)
AtCoderBeginnerContest167 Review & Summary (first half)
AtCoderBeginnerContest177 Review & Summary (first half)
AtCoderBeginnerContest168 Review & Summary (first half)
AtCoderBeginnerContest178 Review & Summary (first half)
AtCoderBeginnerContest171 Review & Summary (first half)
AtCoderBeginnerContest166 Review & Summary (first half)
AtCoderBeginnerContest161 Review & Summary (first half)
AtCoderBeginnerContest172 Review & Summary (first half)
AtCoderBeginnerContest176 Review & Summary (first half)
AtCoderBeginnerContest178 Review & Summary (second half)
AtCoderBeginnerContest161 Review & Summary (second half)
AtCoderBeginnerContest164 Review & Summary (second half)
AtCoderBeginnerContest176 Review & Summary (second half)
AtCoderBeginnerContest168 Review & Summary (second half)
AtCoderBeginnerContest166 Review & Summary (second half)
AtCoderBeginnerContest171 Review & Summary (second half)
AtCoderBeginnerContest174 Review & Summary (second half)
AtCoderBeginnerContest173 Review & Summary (second half)
AtCoderBeginnerContest177 Review & Summary (second half)
AtCoderBeginnerContest180 Review & Summary
AtCoderBeginnerContest181 Review & Summary
AtCoderBeginnerContest182 Review & Summary
AtCoderBeginnerContest183 Review & Summary
AtCoderBeginnerContest179 Review & Summary
AtCoder Review of past questions (first half of 12 / 8,9)