ABC126 A, B, C Explanation (python)

I would like to write a commentary on ABC's A, B, and C problems in Reiwa, hoping that it will be a training to deepen one's understanding and a little help for someone.

A problem

https://atcoder.jp/contests/abc126/tasks/abc126_a

Can it be connected with lower use?

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

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

Output up to the character before k with s [: k-1] Output with s [k-1] .lower () in lowercase k Output k and later with s [k:]

B problem

https://atcoder.jp/contests/abc126/tasks/abc126_b

Judgment is made by looking at the two digits in the latter half of the first two digits. Therefore, at first, the data is received as str type. Convert the 1st, 2nd, 3rd and 4th characters together to int type.


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 problem

https://atcoder.jp/contests/abc126/tasks/abc126_c

I think it means to honestly implement the output method in output example 1. I managed to implement it by looking at the submission results of other people. .. ..


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)

Recommended Posts

ABC127 A, B, C Explanation (python)
ABC126 A, B, C Explanation (python)
ABC128 A, B, C commentary (python)
Solve ABC175 A, B, C in Python
[AtCoder explanation] Control ABC180 A, B, C problems with Python!
[AtCoder explanation] Control ABC188 A, B, C problems with Python!
[AtCoder explanation] Control ABC158 A, B, C problems with Python!
[AtCoder explanation] Control ABC164 A, B, C problems with Python!
[AtCoder explanation] Control ABC168 A, B, C problems with Python!
Solve ABC163 A ~ C with Python
[AtCoder explanation] Control the A, B, C problems of ABC182 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!
ABC166 in Python A ~ C problem
[AtCoder explanation] Control the A, B, C problems of ABC185 with Python!
Solve ABC036 A ~ C in Python
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Solve Atcoder ABC176 (A, B, C, E) in Python
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
Solve ABC037 A ~ C in Python
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
[AtCoder explanation] Control the A, B, C, D problems of ABC183 with Python!
[AtCoder explanation] Control the A, B, C, D problems of ABC181 with Python!
python> keyword arguments> hoge (** {'a': 1,'b': 2,'c': 3})
Solve ABC165 A, B, D in Python
ABC147 C --HonestOrUnkind2 [Python]
Python3> round (a --b, 7)
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
ABC163 C problem with python3
AtCoder ABC 178 Python (A ~ E)
ABC memorandum [ABC163 C --managementr] (Python)
AtCoder ABC 176 Python (A ~ E)
AtCoder ABC 182 Python (A ~ D)
ABC188 C problem with python3
ABC187 C problem with python
AtCoder Beginner Contest 166 A Explanation of Problem "A? C" (Python3, C ++, Java)
Python a + = b and a = a + b are different
ABC memorandum [ABC159 C --Maximum Volume] (Python)
AtCoder Beginner Contest 177 B Problem "Substring" Explanation (Python3, C ++, Java)
Solve ABC166 A ~ D with Python
AtCoder Beginner Contest 167 A Problem "Registration" Explanation (Python3, C ++, Java)
ABC memorandum [ABC161 C --Replacing Integer] (Python)
ABC memorandum [ABC158 C --Tax Increase] (Python)
Solved AtCoder ABC 114 C-755 with Python3
Template AtCoder ABC 179 Python (A ~ E)
[Python] return A [or / and] B
AtCoder Beginner Contest 169 B Problem "Multiplication 2" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 170 A Problem "Five Variables" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 169 A Explanation of Problem "Multiplication 1" (Python3, C ++, Java)
AtCoder Beginner Contest 175 B Problem "Making Triangle" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 175 A Problem "Rainy Season" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 176 B Problem "Multiple of 9" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 174 A Problem "Air Conditioner" Explanation (C ++, Python, Java)
Algorithm in Python (ABC 146 C Binary Search
[Python] [Explanation] AtCoder Typical DP Contest: A Contest
ABC memorandum [ABC157 C --Guess The Number] (Python)
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Solve AtCoder ABC168 with python (A ~ D)
Beginner ABC156 (Python)
AtCoder Beginner Contest 177 A Problem "Don't be late" Explanation (Python3, C ++, Java)