Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Transformation

  Write a program which performs a sequence of commands to a given string $str$. The command is one of:

print a b: print from the a-th character to the b-th character of $str$

reverse a b: reverse from the a-th character to the b-th character of $str$

replace a b p: replace from the a-th character to the b-th character of $str$ with p

  Note that the indices of $str$ start with 0.

Input

  In the first line, a string $str$ is given. $str$ consists of lowercase letters. In the second line, the number of commands q is given. In the next q lines, each command is given in the above mentioned format.

Output

For each print command, print a string in a line.

Constraints

$1 \leq $ length of $str \leq 1000$

$1 \leq q \leq 100$

$0 \leq a \leq b < $ length of $str$

for replace command, $b - a + 1 = $ length of $p$

Sample Input 1

abcde
3
replace 1 3 xyz
reverse 0 2
print 1 4

Sample Output 1

xaze

Sample Input 2

xyz
3
print 0 2
replace 0 2 abc
print 0 2

Sample Output 2

xyz
abc



Sample input:
abcde
3
replace 1 3 xyz
reverse 0 2
print 1 4


Sample output:
xaze

Submission status: Accepted

Solution code:
target = raw_input()

command = []
for _ in range(int(raw_input())):
    command += [raw_input()]

for c in command:
    cmd = c.split()
    if 'replace' == cmd[0]:
        #print   target[0:int(cmd[1])] + cmd[3] + target[int(cmd[2])+1:len(target)]
        target = target[0:int(cmd[1])] + cmd[3] + target[int(cmd[2])+1:len(target)]
    if 'reverse' == cmd[0]:
        #print target[int(cmd[1]):int(cmd[2])+1]
        target = target[0:int(cmd[1])] + target[int(cmd[1]):int(cmd[2])+1][::-1] + target[int(cmd[2])+1:len(target)]
    if 'print' == cmd[0]:
       print target[int(cmd[1]):int(cmd[2])+1]

Submission status: Accepted

Solution code:
target = raw_input()

command = []
for _ in range(int(raw_input())):
    command += [raw_input()]

for c in command:
    cmd = c.split()
    if 'replace' == cmd[0]:
        target = target[0:int(cmd[1])] + cmd[3] + target[int(cmd[2])+1:len(target)]
    if 'reverse' == cmd[0]:
        target = target[0:int(cmd[1])] + target[int(cmd[1]):int(cmd[2])+1][::-1] + target[int(cmd[2])+1:len(target)]
    if 'print' == cmd[0]:
       print target[int(cmd[1]):int(cmd[2])+1]

Submission status: Accepted

Solution code:
# Aizu Problem ITP_1_9_D: Transformation
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


string = [_ for _ in input().strip()]
n = int(input())
for _ in range(n):
    s = input().split()
    a, b = int(s[1]), int(s[2])
    cmd = s[0]
    if cmd == "print":
        print(''.join(string[a:b+1]))
    elif cmd == "reverse":
        tmp = string[a:b+1]
        string[a:b+1] = [_ for _ in tmp[::-1]]
    elif cmd == "replace":
        for p in range(a, b + 1):
            string[p] = s[3][p-a]

Submission status: Accepted

Solution code:
moto = input()
num = int(input())

for i in range(num):
    order = input().split()
    if order[0] == "print":
        m,n=int(order[1]),int(order[2])
        print(moto[m:n+1])
    elif order[0] == "reverse":
        m,n=int(order[1]),int(order[2])
        moto = moto[:m]+moto[m:n+1][::-1]+moto[n+1:]
    elif order[0] == "replace":
        m,n,l=int(order[1]),int(order[2]),order[3]
        moto = moto[:m]+order[3]+moto[n+1:]

Submission status: Accepted

Solution code:
str = [w for w in input()]
q = int(input())
for i in range(q):
    command = [w for w in input().split()]
    command[1] = int(command[1])
    command[2] = int(command[2])
    if command[0] == "print":
        for i in range(command[1], command[2]+1):
            print(str[i], end="")
        print()
    if command[0] == "replace":
        j = command[1]
        for i in range(len(command[3])):
            str[j] = command[3][i]
            j += 1
    if command[0] == "reverse":
        r = []
        for i in range(command[2], command[1]-1, -1):
            r.append(str[i])
        i = command[1]
        for w in r:
            str[i] = w
            i += 1

Submission status: Accepted

Solution code:
str = input()
q = int(input())

for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])

Submission status: Accepted

Solution code:
Str = list(input())
q = int(input())

for i1 in range(q):
    Input = input().split()
    Order = Input[0]
    
    if Order == "print":
        a = int(Input[1])
        b = int(Input[2])
        for i2 in range(a, b + 1):
            print(Str[i2], end = '')
        print()
        continue
    
    if Order == "reverse":
        a = int(Input[1])
        b = int(Input[2])
        work = Str[a: b + 1]
        work.reverse()
        Str[a: b + 1] = work
        continue

    if Order == "replace":
        a = int(Input[1])
        b = int(Input[2])
        p = Input[3]
        Str[a: b + 1] = p
        continue

Submission status: Accepted

Solution code:
s = list(input())
n = int(input())
for i in range(n):
    order = input().split()
    a, b = int(order[1]), int(order[2])+1
    if order[0] == "replace":
        # s = s.replace(s[a:b],order[3])
        s[a:b] = order[3]
    elif order[0] == "reverse":
        t = s[a:b]
        # s = s.replace(s[a:b],t[::-1])
        s[a:b] = t[::-1]
    else:
        t = "".join(s[a:b])
        print(t)

Submission status: Accepted

Solution code:
string = list(input())
times = int(input())
for i in range(times):
    order = input().split()
    if order[0] == "print":
        print("".join(string[int(order[1]):int(order[2]) + 1]))
    elif order[0] == "replace":
        string[int(order[1]):int(order[2]) + 1] = order[3]
    else:
        string[int(order[1]):int(order[2]) + 1] = list(reversed(string[int(order[1]):int(order[2]) + 1]))

Submission status: Accepted

Solution code:
class Reader:
    def __init__(self, s):
        self.t = list(s)

    def __call__(self, s):
        t = s.split()
        l, r = int(t[1]), int(t[2])+1
        if t[0] == "reverse":
            for i, v in zip(range(l,r), reversed(self.t[l:r])):
                self.t[i] = v
        elif t[0] == "replace":
            for i, v in zip(range(l,r), t[3]):
                self.t[i] = v
        else:
            print("".join(self.t[l:r]))

reader = Reader(input())
n = int(input())
for _ in range(n):
    reader(input())

Submission status: Accepted

Solution code:
str=input()
n=int(input())
for i in range(n):
    s=input().split()
    a=int(s[1])
    b=int(s[2])
    if s[0] == 'replace':
        str=str[:a]+s[3]+str[b+1:]
    elif s[0] == 'reverse':
        str=str[:a]+str[a:b+1][::-1]+str[b+1:]
    else:
        print(str[a:b+1])

Submission status: Accepted

Solution code:
s=input()
for i in range(int(input())):
    sou_com=input().split()
    if sou_com[0]=='print':
        print(s[int(sou_com[1]):int(sou_com[2])+1])
    elif sou_com[0]=='reverse':
        s=s[:int(sou_com[1])]\
        +s[int(sou_com[1]):int(sou_com[2])+1][::-1]\
        +s[int(sou_com[2])+1:]
    elif sou_com[0]=='replace':
        s=s[:int(sou_com[1])]\
        +sou_com[3]\
        +s[int(sou_com[2])+1:]

Submission status: Accepted

Solution code:
s = input()
for i in range(int(input())):
    q = input().split()
    op, a, b = q[0], int(q[1]), int(q[2])
    if op == 'print':
        print(s[a : b+1])
    elif op == 'reverse':
        t = s[a : b+1]
        s = s[:a] + t[::-1] + s[b+1:]
    elif op == 'replace':
        s = s[:a] + q[3] + s[b+1:]

Submission status: Accepted

Solution code:
str = raw_input()
q = int(raw_input())

for i in range(q):
	do_list = raw_input().split()
	a = int(do_list[1])
	b = int(do_list[2])
	if do_list[0] == "print":
		print(str[a:(b+1)])
	elif do_list[0] == "reverse":
		part = str[a:(b+1)]
		rev = ""
		for j in range(len(part)):
			rev += part[-j-1]
		if a == 0:
			str = rev + str[(b+1):]
		elif b == len(str)-1:
			str = str[:a] + rev
		else:
			str = str[:a] + rev + str[(b+1):]
	else:
		p = do_list[3]
		if a == 0:
			str = p + str[(b+1):]
		elif b == len(str)-1:
			str = str[:a] + p
		else:
			str = str[:a] + p + str[(b+1):]

Submission status: Accepted

Solution code:
def main():
    m = list(input())
    q = int(input())
    A = []
    for _ in range(q):
        A.append(input().split())

    for x in range(q):
        if A[x][0] == "print":
            A[x][1] = int(A[x][1])
            A[x][2] = int(A[x][2])
            for y in range(A[x][1], A[x][2] + 1):
                if y != A[x][2]:
                    print(m[y], end = "")
                else:
                    print(m[y])
        elif A[x][0] == "reverse":
            A[x][1] = int(A[x][1])
            A[x][2] = int(A[x][2])
            hoge = []
            for y in range(A[x][1], A[x][2] + 1):
                hoge.append(m[y])
            hoge = hoge[::-1]
            i = 0
            for y in range(A[x][1], A[x][2] + 1): 
                m[y] = hoge[i]
                i += 1
        elif A[x][0] == "replace":
            A[x][1] = int(A[x][1])
            A[x][2] = int(A[x][2])
            fuga = list(A[x][3])
            j = 0
            for y in range(A[x][1], A[x][2] + 1):
                m[y] = fuga[j]
                j += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
string = raw_input()
num_order = int(raw_input())
for i in range(num_order):
    command = raw_input().split()
  #  print command
    a, b = map(int, command[1:3])
    if command[0] == "print":
        print string[a:b+1]
    elif command[0] == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif command[0] == "replace":
        p = command[-1]
        string = string[:a] + p + string[b+1:]

Submission status: Accepted

Solution code:
s=' '+input()+' '
for _ in range(int(input())):
    l=input().split()
    o=l[0]
    a=int(l[1])+1; b=int(l[2])+2
    if o=='print': print(s[a:b])
    if o=='reverse': s=s[:a]+s[b-1:a-1:-1]+s[b:]
    if o=='replace': s=s[:a]+l[3]+s[b:]

Submission status: Accepted

Solution code:
def main():

    string = input()
    commands_count = int(input())
    commands = [input().split() for i in range(commands_count)]

    for command in commands:
        a, b = int(command[1]), int(command[2])
        if len(command) == 4:
            string = string[0:a] + command[3] + string[b+1:]
        else:
            if command[0] == 'print':
                print(string[a:b+1])
            else:
                string = string[0:a] + ''.join(list(reversed(string[a:b+1]))) + string[b+1:]

main()

Submission status: Accepted

Solution code:
def str_reverse(s, a, b):
    s_new = s[0:a]
    s_rev = s[a:b+1]
    s_rev_len = len(s_rev)
    for i in range(s_rev_len):
        j = s_rev_len - i - 1
        s_new += s_rev[j]
    s_new += s[b+1:]
    return s_new

def str_replace(s, a, b, new):
    s_new = s[0:a]
    s_new += new
    s_new += s[b+1:]
    return s_new


s = input()
n = int(input())
for q in range(n):
    line = input()
    if line.find('print') == 0:
        cmd, a, b  = line.split()
        a = int(a)
        b = int(b)
        print(s[a:b+1])

    elif line.find('reverse') == 0:
        cmd, a, b  = line.split()
        a = int(a)
        b = int(b)
        s = str_reverse(s, a, b)

    elif line.find('replace') == 0:
        cmd, a, b, p  = line.split()
        a = int(a)
        b = int(b)
        s = str_replace(s, a, b, p)

Submission status: Accepted

Solution code:
s = input()
for i in range(int(input())):
    cmds = input().split()
    cmd = cmds[0]
    a = int(cmds[1])
    b = int(cmds[2])
    if 'replace' == cmd:
        s = s[:a] + cmds[3] + s[b+1:]
    elif 'reverse' == cmd:
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif 'print' == cmd:
        print(s[a:b+1])

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for i in range(q):
    command = input().split()
    command[1] = int(command[1])
    command[2] = int(command[2])
    if command[0] == 'print':
        print(s[command[1]:command[2]+1])
    elif command[0] == 'reverse':
        s = s[command[1]:command[2]+1][::-1].join([s[:command[1]], s[command[2]+1:]])
    elif command[0] == 'replace':
        s = command[3].join([s[:command[1]], s[command[2]+1:]])

Submission status: Accepted

Solution code:
# -*-coding:utf-8

def main():

    inputLine = list(input())

    orderLine = int(input())

    for i in range(orderLine):
        tokens = list(input().split())

        a = int(tokens[1])
        b = int(tokens[2])

        if(tokens[0] == 'print'):
            print( ''.join(inputLine[a:b+1]) )
        elif(tokens[0] == 'reverse'):
            reverseList = inputLine[a:b+1]
            inputLine[a:b+1] = reverseList[::-1]
        elif(tokens[0] == 'replace'):
            replaceList = list(tokens[3])
            inputLine[a:b+1] = replaceList

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    q = int(input())

    for _ in range(q):
        query = input().split()
        op, a, b = query[0:3]
        a, b = int(a), int(b)

        if op == "replace":
            p = query[3]
            s = s[:a] + p + s[b + 1:]
        elif op == "reverse":
            s = s[:a] + s[a:b + 1][::-1] + s[b + 1:]
        elif op == "print":
            print(s[a:b + 1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
for _ in range(int(input())):
 a=input().split()
 if a[0]=='print':print(s[int(a[1]):int(a[2])+1])
 if a[0]=='reverse':
  s=s[0:int(a[1])]+s[int(a[1]):int(a[2])+1][::-1]+s[int(a[2])+1:]
 if a[0]=='replace':
  s=s[0:int(a[1])]+a[3]+s[int(a[2])+1:]

Submission status: Accepted

Solution code:
s=input()
for _ in range(int(input())):
 a=input().split()
 if a[0]=='print':print(s[int(a[1]):int(a[2])+1])
 else:
  t=s[0:int(a[1])]
  t+=s[int(a[1]):int(a[2])+1][::-1]if'reverse'==a[0]else a[3]
  s=t+s[int(a[2])+1:]

Submission status: Accepted

Solution code:
s=input()
for _ in range(int(input())):
 a=input().split()
 if a[0]=='print':print(s[int(a[1]):int(a[2])+1])
 else:
  t=s[int(a[1]):int(a[2])+1][::-1]if'reverse'==a[0]else a[3]
  s=s[0:int(a[1])]+t+s[int(a[2])+1:]

Submission status: Accepted

Solution code:
s=input()
for _ in range(int(input())):
 a=input().split()
 if a[0][0]=='p':print(s[int(a[1]):int(a[2])+1])
 else:
  t=a[3]if'p'==a[0][2]else s[int(a[1]):int(a[2])+1][::-1]
  s=s[0:int(a[1])]+t+s[int(a[2])+1:]

Submission status: Accepted

Solution code:
s=input()
for _ in range(int(input())):
 a=input().split()
 i=int(a[1]);j=int(a[2])
 if a[0][0]=='p':print(s[i:j+1])
 else:
  t=a[3]if'p'==a[0][2]else s[i:j+1][::-1]
  s=s[0:i]+t+s[j+1:]

Submission status: Accepted

Solution code:
s=input()
for _ in range(int(input())):
 a=input().split()
 o=a[0];i=int(a[1]);j=int(a[2])+1
 if'p'==o[0]:print(s[i:j])
 else:
  t=a[3]if'p'==o[2]else s[i:j][::-1]
  s=s[0:i]+t+s[j:]

Submission status: Accepted

Solution code:
s = input()
n = int(input())

l = []
for i in range(n):
    l.append(list(map(str,input().split())))

for i in range(len(l)):
    command = l[i][0]
    a = int(l[i][1])
    b = int(l[i][2])
    c = s[a:b+1]
    if command == "replace":
        s = s[:a] + l[i][3] + s[b+1:]
    elif command == "reverse":
        s = s[:a] + c[::-1] + s[b+1:]
    elif command == "print":
        print(c)

Submission status: Accepted

Solution code:
t = input()
for _ in range(int(input())):
    order = input().split()
    cmd = order[0]
    a, b = map(int,  order[1:3])
    if cmd == 'print':
        print(t[a:b+1])
    elif cmd == 'reverse':
        t = t[:a] + t[a:b+1][b::-1] + t[b+1:]
    else:
        c = order[3]
        t = t[:a] + c + t[b+1:]

Submission status: Accepted

Solution code:
bun=input()
for i in range(int(input())):
    o=input().split()
    o[1],o[2]=int(o[1]),int(o[2])
    if o[0]=='print':
        print(bun[o[1]:o[2]+1])
    elif o[0]=='reverse':
        bun_bun=bun[o[1]:o[2]+1]
        bun_bun=bun_bun[::-1]
        bun=bun.replace(bun[o[1]:o[2]+1],bun_bun)
    elif o[0]=='replace':
        bun=bun[:(o[1])]+o[3]+bun[(o[2]+1):]

Submission status: Accepted

Solution code:
str = input()
str_list = list(str)
q = int(input())
for i in range(q):
    order = input().split()
    if order[0] == 'print':
        for i in range(int(order[1]),int(order[2])+1):
            print("{}".format(str_list[i]),end=(''))
        print('')
    elif order[0] == 'replace':
        word=list(order[3])
        j = 0
        for i in range(int(order[1]),int(order[2])+1):
            str_list[i]=word[j]
            j = j + 1
    elif order[0] == 'reverse':
        word = list(str_list[int(order[1]):int(order[2])+1])
        j = len(word)
        for i in range(int(order[1]),int(order[2])+1):
            str_list[i] = word[j-1]
            j = j - 1

Submission status: Accepted

Solution code:
instr = input()
cnum = int(input())
for i in range(cnum):
    lineSp = input().split()
    cmd = lineSp[0]
    a, b = int(lineSp[1]), int(lineSp[2])
    if cmd == "replace":
        repstr = lineSp[3]
        instr = instr[0:a] + repstr + instr[b + 1:]
    elif cmd == "reverse":
        repstr = instr[a:b + 1][::-1]
        instr = instr[0:a] + repstr + instr[b + 1:]
    else:
        print(instr[a:b + 1])

Submission status: Accepted

Solution code:
w = input()
q = int(input())
for _ in range(q):
    S = input().split()
    s = S[0]
    a, b = map(int, S[1: 3])
    if s == "print":
        print(w[a: b + 1])
    elif s == "reverse":
        w = w[:a] + w[a: b + 1][::-1] + w[b + 1:]
    else:
        w = w[:a] + S[3] + w[b + 1:]

Submission status: Accepted

Solution code:
str = input()
q = int(input())

for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])

Submission status: Accepted

Solution code:
# coding:utf-8
def show(a,b):
    global str
    print str[a:b+1]
def reverse(a,b):
    global str
    t = str[:a]
    t += str[-(len(str)-b):-(len(str)-a+1):-1]
    t += str[b+1:]
    str = t
def replace(a,b,p):
    global str
    t = str[:a]
    t += p
    t += str[b+1:]
    str = t

str = raw_input()
n = input()

for i in range(n):
    command = raw_input().split()
    if command[0] == "replace":
        replace(int(command[1]),int(command[2]),command[3])
    elif command[0] == "reverse":
        reverse(int(command[1]),int(command[2]))
    elif command[0] == "print":
        show(int(command[1]),int(command[2]))

Submission status: Accepted

Solution code:
string = input()
raw = int(input())
for _ in range(raw):
    hoge = input().strip().split()
    if hoge[0] == 'print':
        print (string[int(hoge[1]):int(hoge[2])+1])
    elif hoge[0] == 'reverse':
        string = string[:int(hoge[1])] + string[int(hoge[1]):int(hoge[2])+1][::-1] + string[int(hoge[2])+1:]
    elif hoge[0] == 'replace':
        string = string[:int(hoge[1])] + hoge[3] + string[int(hoge[2])+1:]

Submission status: Accepted

Solution code:
str_in, n = input(), int(input())
for i in range(n):
    com = input().split()
    com_idx = [int(i) for i in com if i.isdigit()]
    if com[0]=="print":
        print(str_in[com_idx[0]:com_idx[1]+1])
    elif com[0]=="reverse":
        str_rev = str_in[com_idx[0]:com_idx[1]+1]
        str_in = str_in[:com_idx[0]] + str_rev[::-1] + str_in[com_idx[1]+1:]
    elif com[0]=="replace":
        str_in = str_in[:com_idx[0]] + com[3] + str_in[com_idx[1]+1:]

Submission status: Accepted

Solution code:
text = list(input())
num = int(input())
for i in range(num):
    cmd = input().split()
    start, end = map(int, cmd[1:3])
    if cmd[0] == 'replace':
        text[start:end+1] = list(cmd[-1])
    elif cmd[0] == 'reverse':
        text[start:end+1] = (text[start:end+1])[::-1]
    elif cmd[0] == 'print':
        print(''.join(text[start:end+1]))

Submission status: Accepted

Solution code:
string = input()
n = int(input())
for i in range(n):
    inp = [x for x in input().split()]
    a = int(inp[1])
    b = int(inp[2])
    if inp[0] == 'print':
        print(string[a:b+1])
    elif inp[0] == 'reverse':
        string = string[:a] + string[a:b+1][::-1] +string[b+1:]
    else:
        string = string[:a] + inp[3] + string[b+1:]

Submission status: Accepted

Solution code:
string = input()
for _ in range(int(input())):
    com = [x for x in input().split()]
    c = com[0]
    a,b = [int(com[i]) for i in range(1,3)]
    if c == 'reverse':
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    if c == 'print':
        print(string[a:b+1])
    if c == 'replace':
        string = string[:a] + com[3] + string[b+1:]

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

in_str = sys.stdin.readline().strip()
q = int(sys.stdin.readline())

for i in range(q):
    command = sys.stdin.readline().split()
    pos_a = int(command[1])
    pos_b = int(command[2])

    if command[0] == 'print':
        print(in_str[pos_a:pos_b+1])
    elif command[0] == 'reverse':
        if pos_a == 0: to_pos = None
        else: to_pos = pos_a - 1
        in_str = in_str[:pos_a] + in_str[pos_b:to_pos:-1] + in_str[pos_b+1:]
    elif command[0] == 'replace':
        in_str = in_str[:pos_a] + command[3] + in_str[pos_b+1:]
    else:
        raise ValueError

Submission status: Accepted

Solution code:
def transformate(s, command):
    command, *op = command.split()

    op[0] = int(op[0])
    op[1] = int(op[1])

    if command == 'replace':
        return s[0:op[0]] + op[2] + s[op[1]+1:]
    elif command == 'reverse':
        return s[0:op[0]] + s[op[0]:op[1]+1][::-1] + s[op[1]+1:]
    elif command == 'print':
        print(s[op[0]:op[1]+1])
        return s

if __name__ == '__main__':
    s = input()
    for _ in range(int(input())):
        s = transformate(s, input())

Submission status: Accepted

Solution code:
line = input()
for _ in range(int(input())):
    x = input().split()
    order = x[0]
    a = int(x[1])
    b = int(x[2])+1
    if order == "print":
        print(line[a:b])
    elif order == "reverse":
        line = line[:a] + line[a:b][::-1] + line[b:]
    elif order == "replace":
        line = line[:a] + x[3] + line[b:]

Submission status: Accepted

Solution code:
# Pythonのスライスは最後が開区間だから癖がある
t = input()
for i in range(int(input())):
    cmd = list(input().split())
    cmd[1] = int(cmd[1])
    cmd[2] = int(cmd[2])
    if cmd[0] == "print":
        print(t[cmd[1] : cmd[2]] + t[cmd[2]])
    elif cmd[0] == "reverse":
        tmp = t[cmd[1] : cmd[2]] + t[cmd[2]]
        tmp = tmp[::-1]
        t = t[:cmd[1]] + tmp + t[cmd[2]+1:]
    elif cmd[0] == "replace":
        t = t[:cmd[1]] + cmd[3] + t[cmd[2]+1:]

Submission status: Accepted

Solution code:
s = input()
n = int(input())
ans = ''
i = 0
while i < n:
    order = list(map(str, input().split(' ')))
    if order[0] == 'print':
        ans += s[int(order[1]):int(order[2])+1] + '\n'
    elif order[0] == 'reverse':
        i1 = int(order[1])
        i2 = int(order[2])
        s0 = s[:i1]
        j = 0
        while j < (i2 - i1 + 1):
            s0 += s[i2 - j]
            j += 1
        s0 += s[i2+1:]
        s = s0
    else:
        i1 = int(order[1])
        i2 = int(order[2])
        s = s[:i1] + order[3] + s[i2+1:]
    i += 1
print(ans[:-1])

Submission status: Accepted

Solution code:
class StringEditor:
    def __init__(self, s):
        self.s = s

    def __str__(self):
        return self.s

    def print(self, start, end):
        """print command

        >>> e = StringEditor('abcde')
        >>> e.print(1, 3)
        bcd
        """
        print(self.s[start:end+1])

    def replace(self, start, end, word):
        """replace command

        >>> e = StringEditor('abcde')
        >>> e.replace(1, 3, 'xyz')
        >>> e.print(0, 4)
        axyze
        """
        self.s = self.s[:start] + word + self.s[end+1:]

    def reverse(self, start, end):
        """reverse command

        >>> e = StringEditor('abcde')
        >>> e.reverse(0, 2)
        >>> e.print(0, 4)
        cbade
        >>> e.reverse(2, 3)
        >>> e.print(0, 4)
        cbdae
        """
        if start > 0:
            rev = self.s[end:start-1:-1]
        else:
            rev = self.s[end::-1]

        self.s = self.s[:start] + rev + self.s[end+1:]


def run():
    s = input()
    num = int(input())
    editor = StringEditor(s)

    for _ in range(num):
        com, *args = input().split()

        if com == 'print':
            start, end = [int(i) for i in args]
            editor.print(start, end)
        elif com == 'reverse':
            start, end = [int(i) for i in args]
            editor.reverse(start, end)
        elif com == 'replace':
            start, end = [int(i) for i in args[0:2]]
            word = args[-1]
            editor.replace(start, end, word)
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
str = input()
q = int(input())

for i in range(q):
    args = input().split()
    order = args[0]
    a = int(args[1])
    b = int(args[2])
    if order == "print":
        print(str[a : b + 1])
    elif order == "reverse":
        str = str[: a] + str[a : b + 1][: : -1] + str[b + 1 :]
    elif order == "replace":
        str = str[: a] + args[3] + str[b + 1 :]

Submission status: Accepted

Solution code:
#coding: utf-8

s = input()
q = int(input())
for i in range(q):
    order = input().split(" ")
    if   order[0] == "print":
        print(s[int(order[1]) : int(order[2])+1])
    elif order[0] == "reverse":
        r = s[int(order[1]) : int(order[2])+1]
        r = r[::-1]
        s = s[:int(order[1])] + r + s[int(order[2])+1:]
    elif order[0] == "replace":
        s = s[:int(order[1])] + order[3] + s[int(order[2])+1:]

Submission status: Accepted

Solution code:
s = input()
for _ in range(int(input())):
  c = input().split()
  a = int(c[1])
  b = int(c[2])
  if c[0] == "replace":
    s = s[:a] + c[3] + s[b+1:]
  elif c[0] == "reverse":
    s = s[:a] + s[a:b+1][::-1] + s[b+1:]
  else:
    print(s[a:b+1])

Submission status: Accepted

Solution code:
string = input()
n = int(input())
print_s=[]
for i in range(n):
    order = [i for i in input().split()]
    if order[0] == "replace":
        string = list(string)
        for i in range(len(order[3])):
            string[int(order[1])+i]=order[3][i]
        string= "".join(string)
    elif order[0] == "reverse":
        string = string.replace(string[int(order[1]):int(order[2])+1],
                                string[int(order[2])-len(string):
                                       int(order[1])-len(string)-1:-1])
    else:
        print_s.append(string[int(order[1]):int(order[2])+1])
for i in range(len(print_s)):
    print(print_s[i])

Submission status: Accepted

Solution code:
s = input()
for _ in range(int(input())):
    o = input().split()
    a, b = map(int, o[1:3])
    b += 1
    c = o[0][2]
    if c == 'p':
        s = s[:a]+o[3]+s[b:]
    elif c == 'i':
        print(s[a:b])
    elif c == 'v':
        s = s[:a]+s[a:b][::-1]+s[b:]

Submission status: Accepted

Solution code:
s=input()
for _ in range(int(input())):
    o=input().split()
    a,b=map(int,o[1:3]);b+=1
    c=o[0][2]
    if c=='p':s=s[:a]+o[3]+s[b:]
    elif c=='i':print(s[a:b])
    elif c=='v':s=s[:a]+s[a:b][::-1]+s[b:]

Submission status: Accepted

Solution code:
w = input()
N = int(input())
for n in range(N):
    o = input().split()
    if o[0] == "print":
        print(w[int(o[1]):int(o[2])+1])
    if o[0] == "reverse":
        a = w[int(o[1]):int(o[2])+1]
        w = w[:int(o[1])] + a[::-1] + w[int(o[2])+1:]
    if o[0] == "replace":
        b = [x for x in w]
        i = [y for y in o[3]]
        for j in range(len(i)):
            b[int(o[1])+j] = i[j]
        w = "".join(map(str,b))

Submission status: Accepted

Solution code:
S=input()
N=int(input())
for i in range(N):
    command=input().split()
    if command[0]=="replace":
        a=int(command[1])
        b=int(command[2])
        x=command[3]
        A=S[:a]
        B=S[b+1:]
        S=A+x+B
    elif command[0]=="reverse":
        a=int(command[1])
        b=int(command[2])
        A=S[:a]
        B=S[a:b+1]
        C=S[b+1:]
        T=""
        for p in range(len(B)):
            T+=B[len(B)-1-p]
        S=A+T+C
    else:
        #command[0]=="print"
        a=int(command[1])
        b=int(command[2])
        print(S[a:b+1])

Submission status: Accepted

Solution code:
def Reverse(str, A, B):
    a = int(A)
    b = int(B)
    if a == 0:
        str = str[0:a] + str[b::-1] + str[b + 1:]
    else:
        str = str[0:a] + str[b:a - 1:-1] + str[b + 1:]
    return str

def Replace(str, a, b, c):
    str2 = ''
    Str = list(str)
    for i in range(int(b) - int(a) + 1):
        Str[i + int(a)] = c[i]
    for i in range(len(Str)):
        str2 += Str[i]
    return str2

str = input()
n = int(input())
for i in range(n):
    a = input()
    A = a.split()
    if A[0] == 'print':
        print(str[int(A[1]):int(A[2]) + 1])
    elif A[0] == 'reverse':
        str = Reverse(str, A[1], A[2])
    elif A[0] == 'replace':
        str = Replace(str, A[1], A[2], A[3])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import math

s = list(input())
q = int(input())

for i in range(q):
    n = list(input().split())
    if 'print' in n:
        for j in range(int(n[1]), int(n[2]) + 1):
            print(str(s[j]), end='')
        print()

    elif 'reverse' in n:
        for k in range(math.floor((int(n[2]) - int(n[1]) + 1) / 2)):
            s[int(n[1]) + k], s[int(n[2]) - k] = s[int(n[2]) - k], s[int(n[1]) + k]

    elif 'replace' in n:
        for l in range(int(n[1]), int(n[2]) + 1):
            s.pop(int(n[1]))

        count  = int(n[1])

        for m in list(n[3]):
            s.insert(count, m)
            count += 1

Submission status: Accepted

Solution code:
#! python3
# transformation.py

sent = input()

def print_(arr):
    global sent
    print(sent[int(arr[0]):int(arr[1])+1])

def reverse_(arr):
    global sent
    sent = sent[:int(arr[0])] + sent[int(arr[0]):int(arr[1])+1][::-1] + sent[int(arr[1])+1:]

def replace_(arr):
    global sent
    sent = sent[:int(arr[0])] + arr[2] + sent[int(arr[1])+1:]

ops = {'print': print_, 'reverse': reverse_, 'replace': replace_}

q = int(input())
for i in range(q):
    arr = input().split()
    ops[arr[0]](arr[1:])

Submission status: Accepted

Solution code:
s=input()
for _ in[0]*int(input()):
 a=input().split()
 o=a[0];i=int(a[1]);j=int(a[2])+1
 if'p'==o[0]:print(s[i:j])
 else:
  t=a[3]if'p'==o[2]else s[i:j][::-1]
  s=s[0:i]+t+s[j:]

Submission status: Accepted

Solution code:
s=input()
for _ in[0]*int(input()):
 a=input().split()
 o=a[0];i,j=map(int,a[1:3]);j+=1
 if'p'==o[0]:print(s[i:j])
 else:s=s[:i]+(a[3]if'p'==o[2]else s[i:j][::-1])+s[j:]

Submission status: Accepted

Solution code:
x = input()
for i in range(int(input())):
	o = input().split()
	a,b = map(int,o[1:3])
	b+=1
	t = o[0][2]
	if t == 'i':
		print(x[a:b])
	elif t =='p':
		x = x[:a] + o[3] + x[b:]
	else:
		x = x[:a] + x[a:b][::-1] + x[b:]