5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Python】AtCoderのA問題を30問だけ解く(for Python初心者)

Last updated at Posted at 2019-09-21

速度に拘ったプログラミングが出来るよう、今月末までにA, B, C問題それぞれ30問ずつ解く。
A問題は組み込み関数を知ってるだけで解けてしまうので、難易度的には低いと思います。
とはいえ、基礎を確実に抑えているか否かによって、成長速度は変わってくると感じているので、焦らず解く。

ここでは、問題の詳細は述べず、単にプログラムを張るに留める。

注釈

入力の受付にinput().split(" ")と書いているが、input().split()でもイケます。(後半で気がついた。)

A - Weather Prediction

S = input()

clouds = ["Sunny", "Cloudy", "Rainy"]

if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
else:
    print("Sunny")

A - Password

N = int(input())
c = N ** 3
print(c)

A - Tenki

S = list(input())
T = list(input())

i = 0
ans_cnt = 0

while i < len(S):
    if S[i] == T[i]:
        ans_cnt += 1
    i += 1

print(ans_cnt)

A. Red or Not

a = int(input())
s = input()

if a >= 3200:
    print(s)
else:
    print("red")

A. +-x

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

result = [A + B, A - B, A * B]
result.sort(reverse=True)
print(result[0])

A. Transfer

A, B, C = map(int, input().split(" "))

if B + C <= A:
    print(0)
else:
    print(C - (A - B))

A - Dodecagon

r = int(input())
print(3 * r ** 2)

A. T or T

N, A, B = map(int, input().split(" "))
print(min(A * N, B))

A. Fifty-Fifty

S = list(input())
S_set = set(S)

for target in S_set:
    if S.count(target) != 2:
        print("No")
        exit()

print("Yes")

A. Security

S = list(input())
i = 0
while i < len(S) - 1:
    if S[i] == S[i+1]:
        print("Bad")
        exit()
    i += 1
print("Good")

A - Rounding

X, A = input().split(" ")

if X < A:
    print(0)
else:
    print(10)

A - Airplane

flight_times = list(map(int, input().split(" ")))
flight_times.sort()
print(flight_times[0] + flight_times[1])

A - Apple Pie

A, P = map(int, input().split(" "))
print(int((A*3+P) / 2))

A - Ferris Wheel

A, B = list(map(int, input().split(" ")))
if A >= 13:
    print(B)
elif 6 <= A <= B:
    print(int(B/2))
else:
    print(0)

A - Changing a Character

N, K = list(map(int, input().split()))
S = list(input())
S[K-1] = S[K-1].lower()
print("".join(S))

A - Biscuit Generator

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

cnt = T//A
print(cnt * B)

A. Buttons

A, B = map(int, input().split())
print(max(2*A-1, 2*B-1, A+B))

A - Five Antennas

import itertools

plots = [int(input()) for _ in range(5)]
k = int(input())

combs = itertools.combinations(plots, 2)
for comb in combs:
    if abs(comb[0]-comb[1]) > k:
        print(":(")
        exit()

print("Yay!")

A - Double Helix

base = {"A": "T", "C": "G", "G": "C", "T": "A"}
print(base[input()])

A - White Cells

H, W = map(int, input().split())
h, w = map(int, input().split())

whole = H*W
points_row = h * W
points_column = w * H
duplicates = h * w

print(whole - (points_row + points_column - duplicates))

A - Favorite Sound

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

if B // A < C:
    print(B // A)
else:
    print(C)

A - Still TBD

from datetime import datetime

S = datetime.strptime(input(), "%Y/%m/%d")
target = datetime(2019, 4, 30)

if S <= target:
    print("Heisei")
else:
    print("TBD")

A - B +/- A

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

if B % A == 0:
    print(A + B)
else:
    print(B - A)

A - Entrance Examination


T, X = map(int, input().split())
print(T/X)

A - Right Triangle

AB, BC, CA = map(int, input().split())
print(int(AB * BC / 2))

A - Christmas Eve Eve Eve

days = {"22": "Christmas Eve Eve Eve", "23": "Christmas Eve Eve", "24": "Christmas Eve", "25": "Christmas"}
print(days[input()])

A - 753

accepted = [3, 5, 7]
x = int(input())

if x in accepted:
    print("YES")
else:
    print("NO")

A - Discount Fare

X, Y = map(int, input().split())
print(int(X + Y/2))

A - Programming Education

N = int(input())
if N == 1:
    print("Hello World")
else:
    A, B = [int(input()) for _ in range(2)]
    print(A + B)

A - AtCoder Beginner Contest 999

n = list(input())
result = ""

for num in n:
    if num == "1":
        result += "9"
    else:
        result += "1"

print(result)

A - Maximize the Formula

choices = list(map(int, input().split()))
choices.sort(reverse=True)
print(int(str(choices[0]) + str(choices[1])) + choices[2])

愚直に解くならこう

from itertools import permutations
from copy import copy

choices = list(map(int, input().split()))
combs = permutations(choices, 2)

res = 0

for comb in combs:
    left = copy(choices)
    for num in comb:
        left.remove(num)
    right = int(str(comb[0]) + str(comb[1]))
    total = left[0] + right
    if total > res:
        res = total

print(res)

最後に

最後まで閲覧いただきありがとうございます。
できるだけ短く、簡潔なコードを書いたつもりですが、アドバイス等頂けますと幸いです・・・!
明日はB問題解くよ!

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?