We participated in AtCorder Beginner Contest 168. It was ABC's 3 questions AC. I'm using Python3.
Take out the rightmost number and divide it into cases.
N = input()
if N[-1] == '3':
print('bon')
elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
print('pon')
else:
print('hon')
It is divided into cases according to the length of the character string, and if it is short, it is output as it is, and if it is long, it is omitted.
K = int(input())
S = input()
if len(S) <= K:
print(S)
else:
print(S[:K] + '...')
Find the minute speed of the long hand and the short hand, and find the angle (difference from the top) at H hours and M minutes. This gives the two sides and the angle between them, so the length of the other side is found by the cosine theorem.
import math
A, B, H, M = map(int,input().split())
T = 60 * H + M
a = (360 /60/ 12) * T
b = ((360 / 60) * T ) % 360
k = abs(a - b)
print(a, b, k)
if k > 180:
kakudo = 360 - k
else:
kakudo = k
X = A ** 2 + B **2 - 2 * A * B * math.cos(math.radians(kakudo)) #Cosine theorem
print(X ** (1/2))
Recommended Posts