0
0

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 3 years have passed since last update.

ABC168

Posted at

AtCorder Beginner Contest 168 に参加しました。
ABCの3問ACでした。
Python3を使用しています。

A問題

一番右の数字を取り出して場合分けします。

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

B問題

文字列の長さで場合分けして、短い場合はそのまま、長い場合は省略して出力します。

K = int(input())
S = input()
if len(S) <= K:
    print(S)
else:
    print(S[:K] + '...')

C問題

長針と短針の分速を求め、H時M分のときの角度(頂上からの差)を求めます。
これにより二辺とその間の角が求められるので余弦定理により、もう一辺の長さを求めます。

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)) # 余弦定理
print(X ** (1/2))
0
0
3

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?