今まで解いたAtcoderの問題を備忘録として残していきます。
自分の為に残していきます。
問題①
a, b = map(int, input().split())
print(a|b)
問題②
s = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
s_index = int(input())
s_index += 1
print(s[:s_index] + s[s_index])
問題③
n = int(input())
ans = format(n, '#X')
ans_cnt = len(ans)
if ans_cnt == 3:
print(ans.replace('X', ''))
else:
print(ans.replace('0X', ''))
問題④
B = int(input())
flg = False
for i in range(1, 15 + 1):
ans = i ** i
if ans == B:
flg = True
print(i)
break
else:
print(-1)
問題⑤
N = int(input())
S = input()
if ('ab' in S or 'ba' in S):
print('Yes')
else:
print('No')
問題⑥
p, q = input().split()
al = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
flg = [3, 1, 4, 1, 5, 9]
place_p = al.index(p)
place_q = al.index(q)
if place_p <= place_q:
ans = sum(flg[place_p:place_q])
print(ans)
else:
ans = sum(flg[place_q:place_p])
print(ans)
問題⑦
n = int(input())
s = input()
flg = True
cnt = 0
cnt_1 = 0
for i in s:
if i == 'M':
cnt += 1
cnt_1 = 0
elif i == 'F':
cnt = 0
cnt_1 += 1
if cnt == 2 or cnt_1 == 2:
flg = False
break
if flg:
print('Yes')
else:
print('No')
問題⑧
a, b, c, d = map(int, input().split())
ans = (a + b) * (c - d)
ans_1 = 'Takahashi'
print(ans)
print(ans_1)
問題⑨
n, m = map(int, input().split())
ans = ''
ans_list = []
flg_lst = [chr(ord("A")+i) for i in range(26)] # アルファベット格納
for i in range(n):
m_list = list(map(int, input().split()))
for i in m_list:
if i == 0:
ans += '.'
else:
a = flg_lst[i - 1] # 配列に格納されている文字を取り出しセットする。
ans += a
ans_list.append(ans)
ans = ''
for ans_value in ans_list:
print(ans_value)
問題⑩
A = list(map(int, input().split()))
cnt = 0
flg_1 = 0 # 乗数
ans = 0 # 答えを格納
for i in A:
if i == 1:
flg_1 = 2 ** cnt
ans += flg_1
cnt += 1
else:
cnt += 1
print(ans)
問題⑪
K = int(input())
k_lst = list(map(int, input().split()))
flg_lst = [0] * K
cnt = 0
ans_lst = []
for i in range(1, K + 1):
ans = k_lst[cnt]
if flg_lst[i - 1] != 1:
if not flg_lst[ans - 1] == 1:
flg_lst[ans - 1] = 1
cnt += 1
ans = flg_lst.count(0)
print(ans)
print(*[i + 1 for i, x in enumerate(flg_lst) if x == 0]) # iが数値、xが配列の値。
問題⑫
S = input()
ans = 1
for i in S:
if i.isupper():
break
else:
ans += 1
print(ans)
問題⑬
S = input()
ans = S.upper()
print(ans)
問題⑭
N = int(input())
n_list = list(map(int, input().split()))
n_list.sort()
even = []
odd = []
cnt = 0
for i in n_list:
if cnt % 2 == 0:
even.append(i)
cnt += 1
else:
odd.append(i)
cnt += 1
a_1 = sum(even)
b_1 = sum(odd)
print(abs(a_1 - b_1))
h, w = (int(_) for _ in input().split(" "))
list_ = list()
sum_ax0 = [0 for wi in range(w)]
for hi in range(h):
line_ = [int(_) for _ in input().split(" ")]
sum_ax0 = [x + y for x, y in zip(sum_ax0, line_)]
list_.append(line_)
sum_ax1 = [sum(l) for l in list_]
for hi in range(h):
vi = [str(sum_ax1[hi] - x + y) for x, y in zip(list_[hi], sum_ax0)]
print(' '.join(vi))
問題⑮
S = input()
ans = len(S)
cnt = 0
for i in S:
if i == '0':
cnt += 1
else:
cnt = 0
if cnt == 2:
cnt = 0
ans -= 1
print(ans)
問題⑯
N = int(input())
s = input()
cnt = s.count('na')
print(s.replace('na', 'nya', cnt))