見出し画像

atcoderアルゴリズム

atcoderで解いた問題を共有します。

問題1

問題
出力

解答コード

def sample1():
    """A - Shift """
a, b = map(int, input().split())
A = list(map(int, input().split()))
for i in range(b):
    n = A.pop(0# 一番前のデータを取り出す
    A.append(0# 一番後ろに0を挿入
for ans in A:
    print(ans, end=' '# 半角区切りで表示

問題2


問題
出力例

解答コード

N = int(input())
num_list = list(map(int, input().split()))
Q = int(input())
ans_list = []
for i in range(Q):
    q_list = list(map(int, input().split()))
    if len(q_list) == 3:
        n = q_list[1# 置き換えの位置
        m = q_list[2# listの最後の要素
        num_list[n - 1] = m # 置き換える位置に代入する。
        n_1 = q_list[1]
    else:
        n_1 = q_list[1]
        ans = num_list[n_1 - 1]
        ans_list.append(ans) # 表示するlistに追加する
for j in ans_list:
    print(j) # 答えを表示

問題3


問題3
出力例

解答コード

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)

以上になります。

この記事が気に入ったらサポートをしてみませんか?