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.

ABC126 A,B,C 解説(python)

Posted at

自らの理解を深めるための修練と誰かの一抹の救いになればと令和のABCのA,B,C問題について解説を書いていきたい。

##A問題
https://atcoder.jp/contests/abc126/tasks/abc126_a

lower使用と連結ができるか

n,k = map(int,input().split())
s = input()

print(s[:k-1]+s[k-1].lower()+s[k:])

s[:k-1]でk字手前の文字までを出力
s[k-1].lower()でk字目を小文字にして出力
s[k:]でk以降を出力

##B問題
https://atcoder.jp/contests/abc126/tasks/abc126_b

最初の2桁後半の2桁の数字をみて判断する。
そのため、最初はstr型でデータを受け取り
1、2字目 3、4字目をまとめてint型に変換する。


s = input()
a = int(s[:2])
b = int(s[2:])
 
if 1 <= a and a <= 12 and 1<= b and b <=12:
    print("AMBIGUOUS")
elif 1 <= a <=12 and (12 < b or b < 1):
    print("MMYY")
elif (12 < a or a < 1) and 1 <= b <= 12:
    print("YYMM")
else:
    print("NA")

##C問題

出力例1にある出し方を愚直に実装しなさいと言うことだと思います。
私は、他の方の提出結果をみてなんとか実装できましたが。。。


n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    j = 0
    if i < k:
        while i*(2**j) < k:
            j += 1
        ans += (1/n)*1/(2**j)
    else:
        ans += (1/n)
print(ans)
0
0
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
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?