AtCoder Beginners Selection 11問をpythonで解いてみた

AtCoderの初心者向け問題集である AtCoder Beginners Selection の11問をPythonで解説します。

目次

AtCoder Beginners Selection

Welcome to AtCoder

a = int(input())
b, c = map(int, input().split())
s = input()

print(f"{a + b + c} {s}")

Product

a, b = map(int, input().split())

if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")

Placing Marbles

s = input()
count = s.count('1')

print(count)

Shift only

N = int(input())

A = list(map(int, input().split()))

count = 0

while all(a % 2 == 0 for a in A):
    A = [a // 2 for a in A]
    count += 1

print(count)

Coins

A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a + 100*b + 50*c == X:
                count += 1

print(count)

Some Sums

N, A, B = map(int, input().split())

total = 0

for i in range(1, N+1):
    digit_sum = sum(map(int, str(i)))
    if A <= digit_sum <= B:
        total += i

print(total)

Card Game for Two

N = int(input())
cards = list(map(int, input().split()))

cards.sort(reverse=True)

alice_score = 0
bob_score = 0

for i in range(N):
    if i % 2 == 0:
        alice_score += cards[i]
    else:
        bob_score += cards[i]

print(alice_score - bob_score)

Kagami Mochi

N = int(input())
d = [int(input()) for _ in range(N)]

unique_diameters = len(set(d))

print(unique_diameters)

Otoshidama

N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 10000*x + 5000*y + 1000*z == Y:
            print(x, y, z)
            exit()

print(-1, -1, -1)

白昼夢

S = input().strip()[::-1]

words = ["dream", "dreamer", "erase", "eraser"]
words = [word[::-1] for word in words]

while len(S) > 0:
    matched = False
    for word in words:
        if S.startswith(word):
            S = S[len(word):]
            matched = True
            break
    if not matched:
        break

if len(S) == 0:
    print("YES")
else:
    print("NO")

Traveling

N = int(input())
prev_t, prev_x, prev_y = 0, 0, 0

for _ in range(N):
    t, x, y = map(int, input().split())
    dist = abs(x - prev_x) + abs(y - prev_y)
    time_diff = t - prev_t

    if dist > time_diff or (time_diff - dist) % 2 != 0:
        print("No")
        exit()

    prev_t, prev_x, prev_y = t, x, y

print("Yes")
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

雇われのシステムエンジニアです。
普段は車載ECUのセキュリティー分野に従事しております。

■保有資格
Salesforce 認定 Platform アプリケーションビルダー
Salesforce 認定 Platform デベロッパー

コメント

コメントする

目次