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:
str=input()
ls=len(str)
Str=[str[i] for i in range(ls)]
q=int(input())
i=0
while i<q:
    Com=input().split()
    command=Com[0]
    a=int(Com[1])
    b=int(Com[2])
    l=len(Com)
    if l>3:
        rep=Com[3]
        Rep=[rep[i] for i in range(b+1-a)]

    if command=="print":
        print("".join(Str[a:b+1]))
    if command=="reverse":
        temp=Str[a:b+1]
        #bは含まない...b=lのときどうすんのさこれ
        #print(temp)
#In Python, strings are not mutable, which means they cannot be changed.
#You can, however, replace the whole variable with the new version of the string.
        for j in range(b+1-a):
            Str[a+j]=temp[b-a-j]
        #print("".join(Str))

    if command=="replace":
        #print(rep)
        for j in range(b+1-a):
            Str[a+j]=Rep[j]
        #print("".join(Str))
    i+=1

Submission status: Accepted

Solution code:
s = list(input())

for i in range(int(input())):
    cmd, a, b, *c = input().split()
    a = int(a); b = int(b)
    if cmd == "print":
        print(*s[a:b+1], sep='')
    elif cmd == "reverse":
        s[a:b+1] = reversed(s[a:b+1])
    else:
        s[a:b+1] = c[0]

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for i in range(q):
    row = list(input().split())
    a = int(row[1])
    b = int(row[2])
    command = row[0]
    if command == "replace":
        p = row[3]
        s = s[:a] + p + s[b+1:]
    elif command == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif command == "print":
        print(s[a:b+1])

Submission status: Accepted

Solution code:
w=raw_input()
n=input()
l=['print','replace','reverse']
for i in range(n):
    c=map(str,raw_input().split())
    if c[0]==l[0]:
        print w[int(c[1]):int(c[2])+1]
    elif c[0]==l[1]:
        w=w[:int(c[1])]+c[3]+w[int(c[2])+1:]
    else:
        w=w[0:int(c[1])]+w[int(c[1]):int(c[2])+1][::-1]+w[int(c[2])+1:]

Submission status: Accepted

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

for i in range(q):
  order = list(map(str, input().split()))
  a = int(order[1])
  b = int(order[2])
  
  if order[0] =='print':
      print(st[a:b+1])
  elif order[0] =='reverse':
      st = st[:a] + st[a:b+1][::-1] + st[b+1:]
  else:
      st = st[:a] + order[3] + st[b+1:]

Submission status: Accepted

Solution code:
char=input()
cnt=int(input())
for _ in range(0,cnt):
    ops = input().split()
    a,b=map(int,ops[1:3])
    if ops[0] == 'print':
        print(char[a:b+1])
    if ops[0] == 'reverse':
        char = char[0:a] + char[a:b+1][::-1] + char[b+1:]
    if ops[0] == 'replace':
        char = char[0:a] + ops[3] + char[b+1:]

Submission status: Accepted

Solution code:
text = input()

q = int(input())

for _ in range(q):

    list_command = list(input().split())
    
    a = int(list_command[1])
    b = int(list_command[2])

    if   list_command[0] == "print":
        print(text[a:b + 1])
    elif list_command[0] == "reverse":
        text = text[:a] + text[a:b+1][::-1] + text[b + 1:]
    elif list_command[0] == "replace":
        text = text[:a] + list_command[3] + text[b + 1:]
    else:
        raise

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for _ in range(q):
    data = input().split()
    method = data[0]
    a, b = map(int, data[1:3])
    if method == 'print':
        print(s[a:b + 1])
        continue
    if method == 'reverse':
        p = s[a:b + 1]
        p = p[::-1]
    elif method == 'replace':
        p = data[3]
    s = s[:a] + p + s[b + 1:]

Submission status: Accepted

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

for _ in range(n):
    line = input().split()
    command = line[0]

    if command == 'replace':
        start, end  = int(line[1]), int(line[2])
        s = s[:start] + line[3] + s[end+1:]
    elif command == 'reverse':
        start, end  = int(line[1]), int(line[2])
        s = s[:start] + s[start:end+1][::-1] + s[end+1:]
    elif command == 'print':
        start, end  = int(line[1]), int(line[2])
        print(f"{s[start:end+1]}")

Submission status: Accepted

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

S = []

for i in range(q) :
  x = list(map(str, input().split()))
  a = int(x[1])
  b = int(x[2]) + 1

  if(x[0] == "print") :
    S.append(s[a:b])
  elif(x[0] == "reverse") :
    rv = s[a:b]
    srv = rv[::-1]  #[::-1]で逆転
    s = s[:a] + srv + s[b:]
  else :
    rp = x[3]
    s = s[:a] + rp + s[b:]

for j in S :
  print(j)

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:
def fun_replace(str1,str2,a,b):
    str1_list = list(str1)
    str2_list = list(str2)
    for i in range(b-a+1):
        str1_list[a+i]=str2_list[i]
    str1_changed = "".join(str1_list)
    return str1_changed

def fun_reverse(str1,a,b):
    tmp_str_list=list(str1[a:b+1])
    tmp_str_list.reverse()
    str1_list = list(str1)
    for i in range(b-a+1):
        str1_list[a+i] = tmp_str_list[i]
    str1_changed = "".join(str1_list)
    return str1_changed

def fun_print(str1,a,b):
    for i in range(a,b+1):
        print("%s"%(str1[i]),end="")
    print()


T = str(input())
change_num=int(input())
for order_num in range(change_num):
    order=input().split()

    if str(order[0]) == 'replace':
        T=fun_replace(T,str(order[3]),int(order[1]),int(order[2]))
    elif str(order[0]) == 'reverse':
        T=fun_reverse(T,int(order[1]),int(order[2]))
    else:
        fun_print(T,int(order[1]),int(order[2]))

Submission status: Accepted

Solution code:
S = input()
M = int(input())
for _ in range(M):
    op, *args = input().split()
    a = int(args.pop(0))
    b = int(args.pop(0))
    if op == "print":
        print(S[a:b + 1])
    elif op == "reverse":
        S = S[:a] + S[a:b + 1][::-1] + S[b + 1:]
    elif op == "replace":
        p = args.pop(0)
        S = S[:a] + p + S[b + 1:]

Submission status: Accepted

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

for _ in range(cnt):
    cmd = input().split()
    a=int(cmd[1])
    b=int(cmd[2]) +1

    if cmd[0] == "print":
        print(s[a:b])

    if cmd[0] == "reverse" :
        s= s[:a] +s[a:b][::-1]+s[b:]

    if cmd[0] == "replace":
        c = cmd[3]
        s = s[:a] + c +s[b:]

Submission status: Accepted

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

result = []

for _ in range(num):

    table = list(map(str, input().split()))
    start = int(table[1])
    end = int(table[2]) + 1

    if table[0] == "print":
        result.append(str_ori[start:end])
    elif table[0] == "reverse":
        rev = str_ori[start:end]
        srev = rev[::-1]
        str_ori = str_ori[:start] + srev + str_ori[end:]
    elif table[0] == "replace":
        rep = table[3]
        str_ori = str_ori[:start] + rep + str_ori[end:]

for p in result:
    print(p)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	s = str(input())
	n = int(input())
	for i in range(n):
		data = input().split()
		if data[0] == "print":
			print(s[int(data[1]):int(data[2])+1])
		elif data[0] == "reverse":
			tmp = s[int(data[1]):int(data[2])+1]
			tmp = [s for s in tmp]
			tmp.reverse()
			rev = "".join(tmp)
			s = s[:int(data[1])]+rev+s[int(data[2])+1:]
		elif data[0] == "replace":
			s = s[:int(data[1])]+data[3]+s[int(data[2])+1:]

Submission status: Accepted

Solution code:
def Print(st,a,b):
    print(st[a:b])
    
def Reverse(st,a,b):
    rev = st[a:b]
    st = st[:a] + rev[::-1] + st[b:]
    
    return st

def Replace(st,a,b,p):
    rep = str(p)
    st = st[:a] + rep + st[b:]
    
    return st

st = input()
num = int(input())
while num > 0:
    com = input().split()
    a = int(com[1])
    b = int(com[2])
    
    if(com[0] == "print"):
        Print(st,a,b+1)
    elif(com[0] == 'reverse'):
        st = Reverse(st,a,b+1)

    elif(com[0] == 'replace'):
        p = str(com[3])
        st = Replace(st,a,b+1,p)
    num -= 1

Submission status: Accepted

Solution code:
str = input()
q = int(input())
for i in range(q):
  lst = list(input().split())
  a = int(lst[1])
  b = int(lst[2])
  if lst[0] == "print":
    print(str[a:b+1])
  elif lst[0] == "reverse":
    s = str[a:b+1]
    ss = "".join(list(reversed(s))) #文字列はイミュータブル(更新不可)なので元のオブジェクトを書き換えることはできない
    t1 = str[0:a]
    t2 = str[a:b+1]
    t3 = str[b+1:len(str)]
    str = t1 + ss + t3
  elif lst[0] == "replace":
    t1 = str[0:a]
    t2 = str[a:b+1]
    t3 = str[b+1:len(str)]
    str = t1 + lst[3] + t3
  else:
    pass

Submission status: Accepted

Solution code:
x = list(input())
num = int(input())

for _ in range(num):
    v = input().split()
    order = v[0]
    if order == 'replace':
        a, b, c =v[1:]
        a, b = int(a), int(b)
        del x[a:b+1]
        for n, v in enumerate(list(c)):
            x.insert(a + n, v)
    elif order == 'print':
        a, b = map(int, v[1:])
        print(''.join(x[a:b+1]))
    elif order == 'reverse':
        a, b = map(int, v[1:])
        c = x[a:b+1]
        del x[a:b+1]
        for n, v in enumerate(reversed(list(c))):
            x.insert(a + n, v)

Submission status: Accepted

Solution code:
s = [*input()]
for _ in range(int(input())):
	l = input().split()
	a = int(l[1])
	b = int(l[2]) + 1
	if l[0] == 'print':
		print(*s[a:b], sep='')
	elif l[0] == 'reverse':
		s[a:b] = reversed(s[a:b])
	elif l[0] == 'replace':
		s[a:b] = l[3]

Submission status: Accepted

Solution code:
x = input()
kaisu =int(input())

for i in range(0, kaisu):
    y = input()
    y = y.split()

    a = int(y[1])
    b = int(y[2]) + 1

    if y[0] == "print":
        print(x[a:b])

    elif y[0] == "replace":
        x = x[0:a] + y[3] + x[b:]

    elif y[0] == "reverse":
        c = x[a:b]
        c = c[::-1]
        x = x[0:a] + c + x[b:]

Submission status: Accepted

Solution code:
# transformation.py
def originalPrint(text,start,end):
    print(text[start: end])
    
def originalReverse(text,start,end):
    head = (text[:start])
    target = (text[start:end])
    sliced = target
    reversed_text = sliced[::-1]
    tail = text[end:]
    # print(head+reversed_text+tail)
    text = head+reversed_text+tail
    return text
    
def orignalReplace(text,start,end, replace_text):
    head = (text[:start])
    tail = text[end:]
    # print(head+replace_text+tail)
    text = head+replace_text+tail
    return text

text = input()
num = int(input())

for i in range(num):
    order_info = input().split()
    order = order_info[0]
    start = int(order_info[1])
    end = int(order_info[2]) + 1
    if order == 'print':
        originalPrint(text, start, end)
    elif order == 'reverse':
        text = originalReverse(text, start, end)
    elif order == 'replace':
        replace_text = order_info[3]
        text = orignalReplace(text, start, end,replace_text)

Submission status: Accepted

Solution code:
s = input()
n = int(input())
for i in range(n):
    command = input().split()
    c1, c2 = int(command[1]), int(command[2])+1
    if command[0] == 'print':
        print(s[c1:c2])
    elif command[0] == 'reverse':
        s0 = list(s[c1:c2])
        s0.reverse()
        s1 = ''.join(s0)
        s = s[:c1]+s1+s[c2:]
    elif command[0] == 'replace':
        s = s[:c1]+command[3]+s[c2:]

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# ITP1_9_D
# 文字列変換

s =input()
n = int(input())

for i in range(n):
    data = list(input().split())
    
    if data[0] == "print":
        print(s[int(data[1]):int(data[2]) + 1] )
    elif data[0] == "reverse":
        rs = s[int(data[1]):int(data[2]) + 1]
        rs = rs[::-1]
        s = s[:int(data[1])] + rs + s[int(data[2]) + 1:]
    else:
        s = s[:int(data[1])] + data[3] + s[int(data[2]) + 1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
string = input()

loop = int(input())

data = []

for i in string:
	data.append(i)

for i in range(loop):
	operate = input().split()

	if operate[0] == "replace":
		a = int(operate[1])
		b = int(operate[2])
		trans = []
		for i in operate[3]:
			trans.append(i)
		ope = 0
		for i in range(a, b+1):
			data[i] = trans[ope]
			ope += 1
	elif operate[0] == "reverse":
		a = int(operate[1])
		b = int(operate[2])
		trans = []
		for i in range(a,b+1):
			trans.append(data[b-i+a])

		ope = 0

		for i in range(a, b+1):
			data[i] = trans[ope]
			ope += 1

	else:	
		a = int(operate[1])
		b = int(operate[2])
		for i in range(a, b+1):
			print(data[i], end = "")
		print()

Submission status: Accepted

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

for i in range(q):
    s = input().strip().split()
    
    start = int(s[1])
    end = int(s[2])+1    

    if s[0] == 'print':
        print(str[start:end])
        
    if s[0] == 'reverse':
        str = list(str)
        str[start:end] = reversed(str[start:end])
        str = ''.join(str)
        
    if s[0] == 'replace':
        str = list(str)
        str[start:end] = list(s[3])
        str = ''.join(str)

Submission status: Accepted

Solution code:
line = input()
N = int(input())
 
for loop in range(N):
 
    input_str = list(input().split())
 
    if input_str[0] == 'replace':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + input_str[3] + line[right:]
 
    elif input_str[0] == 'reverse':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + line[left:right][::-1] + line[right:]
 
    else: #print
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        for i in range(left,right):
            print(line[i],end = "")
        print()

Submission status: Accepted

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

for i in range(q):
        buff = input()
        index = -1
        lst = []
        while True:
                jndex = buff.find(" ", index + 1)
                if jndex == -1:
                        lst.append(buff[index + 1 :])
                        break
                lst.append(buff[index + 1 : jndex])
                index = jndex
        
        lst[1] = int(lst[1])
        lst[2] = int(lst[2])

        if lst[0] == "print":
                print(str[lst[1]:lst[2]+1])
        elif lst[0] == "reverse":
                str = str[:lst[1]] + str[lst[1]:lst[2]+1][::-1] + str[lst[2]+1:]
        elif lst[0] == "replace":
                str = str[:lst[1]] + lst[3] + str[lst[2]+1:]

Submission status: Accepted

Solution code:
inp = list(input()) 
count = int(input())

for i in range(count):
    command = list(input().split())
    #print(command)
    if command[0] == "print":
        a = int(command[1])
        b = int(command[2])
        print("".join(inp[a:b+1]))
    elif command[0] == "reverse":
        a = int(command[1])
        b = int(command[2])
        inp[a:b+1] = reversed(inp[a:b+1])
        #print(inp)
    elif command[0] == "replace":
        a = int(command[1])
        b = int(command[2])
        inp[a:b+1] = command[3]
        #print(inp)

Submission status: Accepted

Solution code:
w = input()
N = int(input())

for i in range(N):
    ilist = input().split()
    a = int(ilist[1])
    b = int(ilist[2])

    if ilist[0] == 'print':
        print(w[a:b+1])
    elif ilist[0] == 'reverse':
        w = w[:a] + w[a:b+1][::-1] + w[b+1:]
    else:
        w = w[:a] + ilist[3] + w[b+1:]

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(n):
    x = list(map(str, input().split()))
    a, b = int(x[1]), int(x[2])
    if x[0] == "print":
        print(line[a:b+1])
    elif x[0] == "reverse":
        line = line[:a] + line[a:b+1][::-1] + line[b+1:]
    else:
        line = line[:a] + x[3] + line[b+1:]

Submission status: Accepted

Solution code:
t = list(input())
n = int(input())
for i in range(n):
    s = input().split()
    if s[0] == "print":
        print("".join(t[int(s[1]):int(s[2])+1]))
    elif s[0] == "reverse":
        for j in range(((int(s[2])-int(s[1]))//2)+((int(s[2])-int(s[1]))%2)):
             temp = t[int(s[1])+j]
             t[int(s[1])+j] = t[int(s[2])-j]
             t[int(s[2])-j] = temp
    elif s[0] == "replace":
        for k in range(len(s[3])):
            t[int(s[1])+k] = s[3][k]

Submission status: Accepted

Solution code:
k = [x for x in input()]
n = int(input())
for _ in range(n):
    command = [_ for _ in input().split()]
    if command[0] == "replace":
        del k[int(command[1]):int(command[2])+1]
        for i in range(len(command[3])):
            k.insert(int(command[1]),command[3][len(command[3])-i-1])
    elif command[0] == "reverse":
        b = k[int(command[1]):int(command[2])+1]
        del k[int(command[1]):int(command[2])+1]
        for i in range(len(b)):
            k.insert(int(command[1]),b[i])
    elif command[0] == "print":
        a = k[:]
        for u in range(int(command[1]),int(command[2])+1):
            print(a[u],end ="")
        else:
            print()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(q):
  order = input().split()
  if order[0] == "print":
    print(string[int(order[1]):int(order[2])+1])
  elif order[0] == "reverse":
    rev_b = int(order[1])
    rev_e = int(order[2])
    if rev_b == 0:
      string = string[rev_e::-1] + string[rev_e+1:]
    else:
      string = string[:rev_b] + string[rev_e:rev_b-1:-1] + string[rev_e+1:]
  elif order[0] == "replace":
    rep_b = int(order[1])
    rep_e = int(order[2])
    string = string[:rep_b] + order[3] + string[rep_e+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
words=str(input())
n=int(input())
for i in range(n):
    order=str(input())
    order_s=order.split()
    if order_s[0]=="print":
        print(words[int(order_s[1]):int(order_s[2])+1])
    if order_s[0]=="reverse":
        w_k=words[int(order_s[1]):int(order_s[2])+1]
        words=words.replace(w_k, w_k[::-1])
    if order_s[0]=="replace":
        k=0
        s_l=list(words)
        for j in range(int(order_s[1]),int(order_s[2])+1):
            s_l[j]=order_s[3][k]
            k+=1
        words="".join(s_l)

Submission status: Accepted

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

printList = []

for i in range(N):
    c = list(map(str, input().split()))
    start = int(c[1])
    end = int(c[2])+1
    
    if c[0] == "print":
        printList.append(s[start:end])
    elif c[0] == "replace":
        r = c[3]
        s = s[:start] + r + s[end:]
    elif c[0] == "reverse":
        r = s[start:end]
        sr = r[::-1]
        s = s[:start] + sr + s[end:]
    
for p in printList:
    print(p)

Submission status: Accepted

Solution code:
import copy
function = 0
start = 1
end = 2
replaceStr = 3
reverseStart=0
reverseEnd=0
str = 3
reverseTarget=[]
reversedStr=[]
inStr = list(input())
outStr = copy.deepcopy(inStr)
commandNumber = int(input())
for currentNumber in range(commandNumber):
    command = input().split(" ") # [commandName, start, end (replaceStr)]
    if command[function] == "print":
        printStart = int(command[start])
        printEnd = int(command[end])
        print("".join(outStr[printStart:printEnd+1]))
    
    elif command[function] == "reverse":
        reverseStart = int(command[start])
        reverseEnd = int(command[end])
        reverseTarget.append(outStr[reverseStart:reverseEnd+1])
        reversedStr = reverseTarget[-1][::-1]
        outStr[reverseStart:reverseEnd+1] = reversedStr
    
    elif command[function] == "replace":
        replaceStart = int(command[start])
        replaceEnd = int(command[end])
        replaceStr = list(command[str])
        outStr[replaceStart:replaceEnd+1] = replaceStr

Submission status: Accepted

Solution code:
# coding: utf-8
s = input().rstrip()
q = int(input().rstrip())
for i in range(q):
    line = input().rstrip().split()
    if line[0] == "print":
        print(s[int(line[1]):int(line[2])+1])
    elif line[0] == "reverse":
        s = s[:int(line[1])] + s[int(line[1]):int(line[2])+1][::-1] + s[int(line[2])+1:]
    elif line[0] == "replace":
        s = s[:int(line[1])] + line[3] + s[int(line[2])+1:]

Submission status: Accepted

Solution code:
word = input()
nums = int(input())

for _ in range(nums):
    row = input().split()
    if row[0] == 'replace':
        s, e, st = int(row[1]), int(row[2]), row[3]
        word = word[:s] + st + word[e+1:]
    elif row[0] == 'reverse':
        s, e = int(row[1]), int(row[2])
        word = word[:s] + ''.join(reversed(word[s:e+1])) + word[e+1:]
    elif row[0] == 'print':
        s, e = int(row[1]), int(row[2])
        print(word[s:e+1])

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for line in range(q):
    op = input().split()
    st, ed = map(int, op[1:3])
    if op[0] == 'print':
        print(s[st:ed + 1])
    elif op[0] == 'reverse':
        if st == 0: 
            s = s[ed:0:-1] + s[0] + s[ed + 1:]
        else: 
            s = s[:st] + s[ed: st-1 :-1] + s[ed + 1:]
    elif op[0] == 'replace':
        s = s[:st] + op[3] + s[ed + 1:]

Submission status: Accepted

Solution code:
s = list(input())

for i in range(int(input())):
    order, a, b, *c = input().split()
    a = int(a)
    b = int(b)
    if order == "print":
        print(*s[a:b+1], sep='')
    if order == "reverse":
        s[a:b+1] = reversed(s[a:b+1])
    if order == "replace":
        s[a:b+1] = c[0]

Submission status: Accepted

Solution code:
string = input()
n = int(input())
for x in range(n):
    command = tuple(map(str, input().split()))
    if command[0] == "print":
        a = int(command[1])
        b = int(command[2]) + 1
        print(string[a:b])
    elif command[0] == "reverse":
        a = int(command[1])
        b = int(command[2]) + 1
        old = string[a:b]
        new = ""
        for y in old:
            new = y + new
        string = string[:a] + new + string[b:]
    else:
        a = int(command[1])
        b = int(command[2]) + 1
        p = command[3]
        string = string[:a] + p + string[b:]

Submission status: Accepted

Solution code:
word = input()
n = int(input())
for i in range(n):
    command = list(input().split())
    temp = ""
    if command[0] == "print":
        print(word[int(command[1]):int(command[2])+1])
    elif command[0] == "reverse":
        temp += word[:int(command[1])]
        for i in range(int(command[2]), int(command[1])-1, -1):
            temp += word[i]
        temp += word[int(command[2])+1:]
        word = temp
    else:
        temp += word[:int(command[1])]
        temp += command[3]
        temp += word[int(command[2])+1:]
        word = temp

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
W = list(input())
N = int(input())

for i in range(N):
    command,a,b,*c = input().split()
    a= int(a) ; b= int(b)
    if command == 'print':
        print(*W[a:b+1],sep='')
    elif command == 'reverse':
        W[a:b+1] = reversed(W[a:b+1])
    else:
        W[a:b+1] = c[0]

Submission status: Accepted

Solution code:
text = input()
n = int(input())
for _ in range(n):
    do = input().split()
    m = int(do[1])
    s = int(do[2])
    if do[0] == "print":
        print(text[m:s + 1])
    elif do[0] == "reverse":
        text = text[0:m] + text[m:s+1][::-1] + text[s + 1:]
    else:
        text = text[0:m] + do[3] + text[s + 1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

#print(s)

n = int(input())
#print(n)

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

Submission status: Accepted

Solution code:
def _print(a,b,s):
    print(s[a:b+1])
def _reverse(a,b,s):
    return s[:a]+s[a:b+1][::-1]+s[b+1:]
def _replace(a,b,p,s):
    return s[:a]+p+s[b+1:]

s = input()
n = int(input())
for i in range(n):
    c = input().split()
    if c[0] == "print":
        _print(int(c[1]),int(c[2]),s)
    elif c[0] == "reverse":
        s = _reverse(int(c[1]),int(c[2]),s)
    else:
        s = _replace(int(c[1]),int(c[2]),c[3],s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
strlist = list(input())
q = int(input())
for n in range(q):
    coms = input().split()
    if coms[0] == 'print':
        print(''.join(strlist[int(coms[1]):int(coms[2])+1]))
    elif coms[0] == 'reverse':
        #print(strlist)
        #print(strlist[int(coms[1]):int(coms[2])+1])
        new = list(reversed(strlist[int(coms[1]):int(coms[2])+1]))
        #print(new)
        strlist[int(coms[1]):int(coms[2])+1] = new
        #print(strlist)
    elif coms[0] == 'replace':
        strlist[int(coms[1]):int(coms[2])+1] = list(coms[3])[0:]
        #print(strlist)

Submission status: Accepted

Solution code:
import sys


def print_str(str, a, b):
    print(str[a:b+1])


def reverse_str(str, a, b):
    return str[:a] + str[a:b+1][::-1] + str[b+1:]


def replace_str(str, a, b, p):
    return str[:a] + p + str[b+1:]


str = sys.stdin.readline().strip()
num_commands = int(sys.stdin.readline())

for _ in range(num_commands):
    command, *args = sys.stdin.readline().strip().split()
    if command == 'print':
        print_str(str, int(args[0]), int(args[1]))
    elif command == 'reverse':
        str = reverse_str(str, int(args[0]), int(args[1]))
    elif command == 'replace':
        str = replace_str(str, int(args[0]), int(args[1]), args[2])

Submission status: Accepted

Solution code:
s=list(input())

for i in range(int(input())):
    cmd,a,b,*c=input().split()
    a,b=int(a),int(b)
    
    if cmd=="print":
        print(*s[a:b+1],sep="")
    elif cmd=="reverse":
        s[a:b+1]=s[a:b+1][::-1]
    else:
        s[a:b+1]=c[0]

Submission status: Accepted

Solution code:
text = input()
n = int(input())
for i in range(n):
    cmd, *arg = input().split()
    arg0, arg1 = int(arg[0]), int(arg[1])
    if cmd == 'print':
        print(text[arg0:arg1+1])
    elif cmd == 'reverse':
        text = text[:arg0] + text[arg0:arg1+1][::-1] + text[arg1+1:]
    else: # replace
        text = text[:arg0] + arg[2] + text[arg1+1:]

Submission status: Accepted

Solution code:
def hyouji(moji,a,b):
    for j in range(a,b):
        print(moji[j],end="")
    print()

def gyakujun(moji,a,b):
    moji1=[moji[i] for i in range(a,b)]
    moji1.reverse()
    for i in range(a,b):
        moji[i]=moji1[i-a]
    return moji
    
def replace(moji,a,b,p):
    for i in range(a,b):
        moji[i]=p[i-a]
    return moji

nyuryoku=input()
moji=[]

for i in nyuryoku:
    moji.append(i)

kaisu=int(input())

for j in range(kaisu):
    command=list(map(str,input().split()))
    p=[]
    meirei=command[0]
    a=int(command[1])
    b=int(command[2])+1
    if len(command)==4:
        for i in command[3]:
            p.append(i)
    if meirei=="print":
        hyouji(moji,a,b)
    elif meirei=="reverse":
        gyakujun(moji,a,b)
    elif meirei=="replace":
        replace(moji,a,b,p)