問題
B – 文字列の反転
回答
S = input() N = int(input()) LR = [list(map(int, input().split())) for _ in range(N)] ans = S for lr in LR: left = lr[0] - 1 right = lr[1] - 1 ans = ans[:left] + ans[left:right+1][::-1] + ans[right+1:] print(ans)
Freedom is a responsible choice.
S = input() N = int(input()) LR = [list(map(int, input().split())) for _ in range(N)] ans = S for lr in LR: left = lr[0] - 1 right = lr[1] - 1 ans = ans[:left] + ans[left:right+1][::-1] + ans[right+1:] print(ans)