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:
s = input()
q = int(input())
for i in range(q):
    tmp = input()
    if tmp[:3] == 'pri':
        o, a, b = tmp.split()
        a = int(a)
        b = int(b)
        print(s[a:b+1])
    elif tmp[:3] == 'rev':
        o, a, b = tmp.split()
        a = int(a)
        b = int(b)
        sl = list(s)
        sl[a:b+1] = reversed(sl[a:b+1])
        s = ''.join(sl)
    else :
        o, a, b, p = tmp.split()
        a = int(a)
        b = int(b)
        sl = list(s)
        sl[a:b+1] = p
        s = ''.join(sl)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def transform():
    text = input()
    num_order = int(input())

    for _ in range(num_order):
        order = input().split()
        a = int(order[1])
        b = int(order[2])

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


if __name__ == "__main__":
    transform()

Submission status: Accepted

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

for i in range(N):
    cmd = list(map(str, input().split()))
    if cmd[0] == 'replace':
        a, b, c = int(cmd[1]), int(cmd[2]), cmd[3]
        if a == 0:
            s = cmd[3] + s[b+1:]
        else:
            s = s[0:a] + cmd[3] + s[b+1:]
    elif cmd[0] == 'reverse':
        a, b = int(cmd[1]), int(cmd[2])
        ss = s[a:b+1]
        ss = list(reversed(ss))
        ss = ''.join(ss)
        if a == 0:
            s = ss + s[b+1:]
        else:
            s = s[0:a] + ss + s[b+1:]
    elif cmd[0] == 'print':
        a, b = int(cmd[1]), int(cmd[2])
        print(s[a:b+1])

Submission status: Accepted

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

for i in range(n):
    order = input().split()
    a,b = map(int, order[1:3])
    
    if order[0] == "print":
        print(ori[a:b+1])
    elif order[0] == "reverse":
        tmp=ori[a:b+1]
        ori = ori[:a]+tmp[::-1]+ori[b+1:]
    else:
        ori = ori[:a] + order[3] + ori[b+1:]

Submission status: Accepted

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

for i in range(q):
    order = input().split()
    op = order[0]
    a = order[1]
    b = order[2]
    a = int(a)
    b = int(b)

    if op == "replace":
        p = order[3]
        STR = STR[:a] + p + STR[b+1:]
    elif op == "reverse":
        re_STR = STR[a:b+1]
        STR = STR[:a] + re_STR[::-1] + STR[b+1:]
    elif op == "print":
        print(f"{STR[a:b+1]}")

Submission status: Accepted

Solution code:
string = [x for x in input()]
q = int(input())

for i in range(q):
    order_list = [x for x in input().split()]
    a = int(order_list[1])
    b = int(order_list[2])
    if order_list[0] == "print":
        print("".join(string[a:b+1]))
    elif order_list[0] == "reverse":
        rev = reversed(string[a:b+1])
        rev_s = list(rev)
        string = string[:a] + rev_s + string[b+1:]
    elif order_list[0] == "replace":
        replace_str = [x for x in order_list[3]]
        string = string[:a] + replace_str + string[b+1:]
    else:
        None

Submission status: Accepted

Solution code:
s = list(input())
q = int(input())
for i in range(q) :
    order = list(input().split())
    if order[0] == "print" :
        for n in range(int(order[1]), int(order[2])+1) :
            print(s[n], sep="", end="")
        print()
        
    elif order[0] == "reverse" :
        new_s = s[int(order[1]) : int(order[2])+1]
        new_s.reverse()
        s[int(order[1]) : int(order[2])+1] = new_s
    
    elif order[0] == "replace" :
        s[int(order[1]) : int(order[2])+1] = list(order[3])

Submission status: Accepted

Solution code:
t = input()
for _ in[0]*int(input()):
    cmd = input().split()
    if len(cmd) > 3:
        head, a, b, rt = cmd
    else:
        head, a, b = cmd
    a = int(a)
    b = int(b)

    if head == 'print':
        pt = t[a:(b+1)]
        print(pt)
    if head == 'reverse':
        t = t[:a] + ''.join(list(reversed(t[a:(b+1)]))) + t[(b+1):]
    if head == 'replace':
        t = t[:a] + rt + t[(b+1):]

Submission status: Accepted

Solution code:
s = input()
n = int(input())
for _ in range(n):
    ins, *args = input().split()
    if ins == 'print':
        start, end = int(args[0]), int(args[1])+1
        print(s[start:end])
    elif ins == 'reverse':
        start, end = int(args[0]), int(args[1])+1
        s = s[:start] + s[start:end][::-1] + s[end:]
    else:
        start, end, new = int(args[0]), int(args[1])+1, args[2]
        s = s[:start] + args[2] + s[end:]

Submission status: Accepted

Solution code:
target = input()
num_order = int(input())

for _ in range(num_order):
    order = input().split()
    a = int(order[1])
    b = int(order[2])
    
    if order[0] == "print":
        print(target[a:b + 1])
    elif order[0] == "reverse":
        target = target[:a] + "".join(list(reversed(target[a:b + 1]))) + target[b + 1:]
    else:
        p = order[3]
        target = target[:a] + p + target[b + 1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
target = input()
m = int(input())
for i in range(m):
    arr= input().split()
    if arr[0] == 'print':
        print(eval('target[' + eval('arr[1]') + ':' + str(int(eval('arr[2]'))+1)+ ']'))
    if arr[0] == 'reverse':
        s_str = eval('target[' + eval('arr[1]') + ':' + str(int(eval('arr[2]'))+1)+ ']')
        target = eval('target[:' +eval('arr[1]') +']') + ''.join(list(reversed(s_str))) + eval('target[' +str(int(eval('arr[2]'))+1) +':]')
    if arr[0] == 'replace':
        target = eval('target[:' +eval('arr[1]') +']') + eval('arr[3]') + eval('target[' + str(int(eval('arr[2]'))+1) +':]')

Submission status: Accepted

Solution code:
def itp_replace(stri,a,b,c):
    a = int(a)
    b = int(b)
    return stri[:a] + c + stri[b+1:]

def itp_reverse(stri,a,b):
    a = int(a)
    b = int(b)
    return stri[:a] + stri[a:b+1][::-1]+stri[b+1:]

def itp_print(stri,a,b):
    a = int(a)
    b = int(b)
    print(stri[a:b+1])

test_str = input()
test_num = int(input())
order = []
for a in range(test_num):
    temp = input().split()
    order.append(temp)

for a in order:
    if a[0] == 'replace':
        test_str = itp_replace(test_str,a[1],a[2],a[3])
    if a[0] == 'reverse':
        test_str = itp_reverse(test_str,a[1],a[2])
    if a[0] == 'print':
        itp_print(test_str,a[1],a[2])

Submission status: Accepted

Solution code:
l = input()
n = int(input())
for i in range(n):
    s = input().split()
    if s[0] == 'replace':
        l=l[0:int(s[1])] + s[3] + l[int(s[2])+1:len(l)]
    elif s[0] == 'reverse':
        l = l[0:int(s[1])] + l[int(s[1]):int(s[2])+1][::-1] + l[int(s[2])+1:len(l)]
    else:
        print(f"{l[int(s[1]):int(s[2])+1]}")

Submission status: Accepted

Solution code:
def main():
  s = list(input())
  num = int(input())
  while num > 0:
    m = list(input().split())
    if m[0] == 'print':
      print(''.join(s[int(m[1]):(int(m[2]) + 1)]))
    elif m[0] == 'reverse':
      temp = s[int(m[1]):(int(m[2]) + 1)]
      temp.reverse()
      for i,v in enumerate(temp):
        s[int(m[1]) + i] = v
    elif m[0] == 'replace':
      temp = list(m[3])
      for i,v in enumerate(temp):
        s[int(m[1]) + i] = v
    num -= 1
main()

Submission status: Accepted

Solution code:
string = input()
q = int(input())
for _ in range(q):
    operation = tuple(input().split())
    if operation[0] == 'print':
        print(string[int(operation[1]):int(operation[2]) + 1])
    elif operation[0] == 'reverse':
        if int(operation[1]) - 1 < 0:
            string = string =  string[:int(operation[1])] + string[int(operation[2])::-1] + string[int(operation[2]) + 1:]
        else:
            string =  string[:int(operation[1])] + string[int   (operation[2]):int(operation[1]) - 1:-1] + string  [int(operation[2]) + 1:]
    elif operation[0] == 'replace':
        string = string[:int(operation[1])] + operation[3] + string[int(operation[2]) + 1:]

Submission status: Accepted

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

for i in range(n):
    order = input().split()
    a, b= map(int, order[1:3])
    if order[0] == "print":
        print(text[a:b+1])
    elif order[0] == "reverse":
        re_text = text[a:b+1]
        text = text[:a] + re_text[::-1] + text[b+1:]
    else :
        text = text[:a] + order[3] + text[b+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 = 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:
istr = input()
iq = int(input())
arr = []
for i in range(0, iq):
	arr.append(list(input().split()))

#print(arr)

for i in arr:
	cmd = i[0]
	a, b = int(i[1]), int(i[2])
	if cmd == 'print':  # strのa文字目からb文字目までを出力する。
		print(istr[a:b + 1])
	elif cmd == 'reverse':  # strのa文字目からb文字目までを逆順にする。
		stemp = ''
		for i in range(b, a - 1, -1):
			stemp = stemp + istr[i]
		istr = istr[:a] + stemp + istr[b + 1:]
	elif cmd == 'replace':  # strのa文字目からb文字目までをpに置き換える。
		p = i[3]
		istr = istr[:a] + p + istr[b + 1:]

#print(istr)

Submission status: Accepted

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

  for _ in range(q):
    order = list(input().split())
    a,b = int(order[1]), int(order[2])

    if order[0] == 'print':
      print(s[a:b+1])
    elif order[0] == 'reverse':
      s = s[:a] + ''.join(list(reversed(s[a:b+1]))) + s[b+1:]
    else:
      p = order[3]
      s = s[:a] + p + s[b+1:]

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(q):
    m = input().split()
    x = int(m[1])
    y = int(m[2])
    if m[0] == "print":
        print(s[x:y+1])
    elif m[0] == "reverse":
        s = s[0:x] + "".join(list(reversed(s[x:y+1]))) + s[y+1:]
    else:
        s = s[0:x] + m[3] + s[y+1:]

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    run_list = list(input().split())
    if run_list[0] == "print":
        a = int(run_list[1])
        b = int(run_list[2])
        print(S[a:b+1])
    elif run_list[0] == "reverse":
        a = int(run_list[1])
        b = int(run_list[2])
        S = S[:a] + S[a:b+1][::-1] + S[b+1:]

    else:
        a = int(run_list[1])
        b = int(run_list[2])
        p = run_list[3]
        S = S[:a] + p + S[b+1:]

Submission status: Accepted

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

for t in range(n):
    order = list(input().split())

    if "replace" == order[0]:
        left = int(order[1])
        right = int(order[2])
        text = text[:left] + order[3] + text[right + 1:]
    elif "reverse" == order[0]:
        left = int(order[1])
        right = int(order[2])
        text = text[:left] + text[left:right + 1][::-1] + text[right + 1:]
    elif "print" == order[0]:
        print(text[int(order[1]): int(order[2]) + 1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def print_list(s, a, b):
    print(s[a:b+1])

def reverse_list(s, a, b):
    s1 = "".join(s[:a])
    s2 = "".join(reversed(s[a:b+1]))
    s3 = "".join(s[b+1:])
    return list(s1+s2+s3)

def replace_list(s, a, b, p):
    s1 = "".join(s[:a])
    s3 = "".join(s[b+1:])
    return list(s1+p+s3)

s = list(input())
pl = []
cmd = []
n = int(input())
i = 0

while n > i:
    cmd = input().split()
    if cmd[0] == "print":
        pl.append("".join(s[int(cmd[1]):int(cmd[2])+1]))
    elif cmd[0] == "reverse":
        s = reverse_list(s, int(cmd[1]), int(cmd[2]))
    elif cmd[0] == "replace":
        s = replace_list(s, int(cmd[1]), int(cmd[2]), cmd[3])
    i += 1

for p in pl:
    print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

string = list(input())
q = int(input())

def print_func(head, end):
    string_p = ''
    for i in range(head,end + 1):
        string_p += string[i]
    print(string_p)

def reverse_func(head, end):
    i = 0
    while head + i <= end - i:
        string[head + i],string[end - i] = string[end - i],string[head + i]
        i += 1

def replace_func(head, end, r_str):
    l_r_str = list(r_str)
    for i in range(end - head + 1):
        string[head + i] = l_r_str[i]

for i in range(q):
    l = list(input().split())
    l[1] = int(l[1]); l[2] = int(l[2])
    if l[0] == 'print':
        print_func(l[1],l[2])
    elif l[0] == 'reverse':
        reverse_func(l[1],l[2])
    else:
        replace_func(l[1],l[2],l[3])

Submission status: Accepted

Solution code:
m = input()
n = int(input())
for i in range(n):
    ord = input().split()
    a,b =map(int,ord[1:3])
    if ord[0]=='print':
        print(m[a:b+1])
    elif ord[0]=='reverse':
        rev = m[a:b+1]
        m = m[:a]+rev[::-1]+m[b+1:]
    else:
        rep = ord[3]
        m=m[:a]+rep+m[b+1:]

Submission status: Accepted

Solution code:
strings = input()

q = int(input())

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

Submission status: Accepted

Solution code:
def resolve():
    S = input()
    N = int(input())
    L = [list(map(str, input().split())) for _ in range(N)]
    
    for i in range(N):
        start = int(L[i][1])
        end = int(L[i][2]) + 1
        if L[i][0] == 'print':
            print(S[start:end])
        elif L[i][0] == 'reverse':
            S = S[:start] + S[start:end][::-1] + S[end:]
        else:
            S = S[:start] + L[i][3] + S[end:]

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(q):
    l = input().split()
    cmd = l[0]
    a = int(l[1])
    b = int(l[2])
    if cmd == 'print':
        print(''.join(str[a:b+1]))
    elif cmd == 'reverse':
        str[a:b+1] = reversed(str[a:b+1])
    else:
        str[a:b+1] = l[3]

Submission status: Accepted

Solution code:
def defPrint(s,e):
  global str
  print(str[s:e+1])

def defReverse(s,e):
  global str
  strList = list(str)
  rStrList = strList[s:e+1][::-1]
  for i,x in enumerate(rStrList) :
    strList[s + i] = x
  str = "".join(strList)  
  
def defReplace(s,e,r):
  global str
  if s == 0:
    str = r + str[e+1:]
  else:
    str = str[0:s] + r + str[e+1:]

str = input()
q = int(input())

for i in range(q):
  cmd = list(input().split(" "))
  if cmd[0] == 'print' :
    defPrint(int(cmd[1]),int(cmd[2]))
  if cmd[0] == 'reverse' :
    defReverse(int(cmd[1]),int(cmd[2]))
  if cmd[0] == 'replace' :
    defReplace(int(cmd[1]),int(cmd[2]),cmd[3])

Submission status: Accepted

Solution code:
str = str(input())
q = int(input())
for i in range(q):
    order = input().split()
    if order[0] == "print":
        print(str[int(order[1]):int(order[2])+1])
    elif order[0] == "reverse":
        str = str[:int(order[1])] + str[int(order[1]):int(order[2])+1][::-1] + str[int(order[2])+1:]
        # print(str)
    elif order[0] == "replace":
        str = str[:int(order[1])] + order[3] + str[int(order[2])+1:]
        # print(str)
    else:
        pass

Submission status: Accepted

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

for _ in range(n):
    command = input().split() 
    if command[0] == "replace" :
        text = text[:int(command[1])] + command[3] + text[int(command[2])+1:]
        #print(text)
    elif command[0] == "print" :
        print(text[int(command[1]):int(command[2])+1])
        
    elif command[0] == "reverse" :
        rev_text = text[int(command[1]):int(command[2])+1]
        text = text.replace(text[int(command[1]):int(command[2])+1],rev_text[::-1])

Submission status: Accepted

Solution code:
base_str = input()
order_num = int(input())
for i in range(order_num):
    order_str = input().split()

    order_s = int(order_str[1])
    order_e = int(order_str[2])
    if order_str[0] == 'print':
        print('{}'.format(base_str[order_s : order_e + 1]))
    elif order_str[0] == 'reverse':
        if len(base_str) == order_e:
            tmp = base_str[order_s:]
        else:
            tmp = base_str[order_s:order_e + 1]
        tmp_r = tmp[::-1]
        if order_s -1 < 0:
            tmp_new = tmp_r + base_str[order_e + 1:]
        else:
            tmp_new = base_str[:order_s] + tmp_r + base_str[order_e + 1:]
        base_str = tmp_new
    elif order_str[0] == 'replace':
        tmp = base_str[:order_s] + order_str[3] + base_str[order_e + 1:]
        base_str = tmp

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    str = input()
    q = int(input())
    for _ in range(0, q):
        queries = input().split()
        command = queries[0]
        if command == 'print':
            a = int(queries[1])
            b = int(queries[2])
            print(str[a:b + 1])
        elif command == 'reverse':
            a = int(queries[1])
            b = int(queries[2])
            str = str[:a] + ''.join(list(reversed(str[a:b + 1]))) + str[b + 1:]
        elif command == 'replace':
            a = int(queries[1])
            b = int(queries[2])
            p = queries[3]
            str = str[:a] + p + str[b + 1:]

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def p (a:int,b:int):
    print (s[a:b+1])

def rev (a:int,b:int):
    tmp = s[a:b+1]
    return s[:a]+tmp[::-1]+s[b+1:]

def rep (a:int,b:int,p:str):
    return s[:a]+p+s[b+1:]

for _ in range(n):
    i = input().split()
    if i[0] == "print":
        p (int(i[1]),int(i[2]))
    elif i[0] == "reverse":
        s = rev (int(i[1]),int(i[2]))
    else:
        s = rep (int(i[1]),int(i[2]),i[3])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str = input()
question = int(input())
for q in range(question):
    line = input()
    if line.find("print") != -1:
        order, a, b = (x for x in line.split())
        print(str[int(a):int(b)+1])
    elif line.find("reverse") != -1:
        order, a, b = (x for x in line.split())
        if(a == 0): str = str[int(a):int(b)+1][::-1] + str[int(b)+1:len(str)]
        else: str = str[:int(a)] + str[int(a):int(b)+1][::-1] + str[int(b)+1:len(str)]
    elif line.find("replace") != -1:
        order, a, b, word = (x for x in line.split())
        str = str[:int(a)] + word + str[int(b)+1:len(str)]

Submission status: Accepted

Solution code:
def print_command(string, a, b):
    a, b = int(a), int(b)

    print(string[a:b + 1])

    return string


def reverse_command(string, a, b):
    a, b = int(a), int(b)

    return string[:a] + (string[a:b + 1])[::-1] + string[b + 1:]


def replace_command(string, a, b, replace):
    a, b = int(a), int(b)

    return string[:a] + replace + string[b + 1:]


if __name__ == "__main__":
    string = input()

    num_commands = int(input())

    commands = []

    for _ in range(num_commands):
        commands.append(input().split())

    command_function_table = {
        "print": print_command,
        "reverse": reverse_command,
        "replace": replace_command
    }

    for command in commands:
        string = command_function_table[command[0]](string, *(command[1:]))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    list1 = input().split()
    if list1[0] == "print":
        print("".join(S[int(list1[1]):int(list1[2])+1]))
    elif list1[0] == 'reverse':
        S[int(list1[1]):int(list1[2])+1] = reversed(S[int(list1[1]):int(list1[2])+1])
    else:
        S[int(list1[1]):int(list1[2])+1] = list1[3]

Submission status: Accepted

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

while N > 0:
    command = input().split()

    if command[0] == "print":
        a = int(command[1])
        b = int(command[2])

        print(S[a:b+1])
    elif command[0] == "reverse":
        a = int(command[1])
        b = int(command[2])

        S = S[:a]+S[a:b+1][::-1]+S[b+1:]
    

    else:
        a = int(command[1])
        b = int(command[2])
        p = command[3]

        S = S[:a] + p + S[b+1:]


    N -= 1

Submission status: Accepted

Solution code:
a = input()
q = int(input())
s = [input().split() for i in range(q)]

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    command = list(input().split())

    if command[0] == 'replace':
        a = int(command[1])
        b = int(command[2]) + 1
        s = s[:a] + command[3] + s[b:]
    elif command[0] == 'reverse':
        a = int(command[1])
        b = int(command[2]) + 1
        s = s[:a] + s[a:b][::-1] + s[b:]
    else:
        a = int(command[1])
        b = int(command[2]) + 1
        print(s[a:b])

Submission status: Accepted

Solution code:
s = input()
for i in [0]*int(input()):
    l = input().split()
    if l[0] == "print":print(s[int(l[1]):int(l[2])+1])
    elif l[0] == "replace":s = s[0:int(l[1])] + l[3] + s[int(l[2])+1:]
    else:s = s[:int(l[1])] + "".join(reversed(s[int(l[1]):int(l[2])+1])) +s[int(l[2])+1:]

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for i in range(q):
    line = input()
    if 'print' in line:
        op, a, b = line.split()
        a = int(a)
        b = int(b)
        print(s[a:b+1])
    elif 'reverse' in line:
        op, a, b = line.split()
        a = int(a)
        b = int(b)
        reversed_substring = ''.join(list(reversed(s[a:b+1])))
        s = s[:a] + reversed_substring + s[b+1:]
    elif 'replace' in line:
        op, a, b, p = line.split()
        a = int(a)
        b = int(b)
        s = s[:a] + p + s[b+1:]

Submission status: Accepted

Solution code:
string = str(input())
n = int(input())
conversion = [input().split() for i in range(n)]

for conv in conversion:
    func = conv[0]
    if func == "replace":
        a, b, p = int(conv[1]), int(conv[2])+1, conv[3]
        string = string[:a] + p + string[b:]
    else:
        a, b = int(conv[1]), int(conv[2]) + 1
        if func == "print":
            print(string[a:b])
        else:
            string = string.replace(string[a:b], string[a:b][::-1])

Submission status: Accepted

Solution code:
str=input()
str=list(str)
N=int(input())
for i in range(N):
    A=list(input().split())
    A[1],A[2]=[int(A[1]),int(A[2])]
    
    if A[0]=="print":
        tmp=[]
        for j in range(A[1],A[2]+1):
            tmp+=str[j]
        print("".join(tmp))
        
    elif A[0]=="reverse":
        tmp=[]
        for j in range(0,A[2]-A[1]+1):
            tmp+=str[A[2]-j]
        for j in range(0,A[2]-A[1]+1):
            str[A[1]+j]=tmp[j]
    elif A[0]=="replace":
        rep=list(A[3])
        for j in range(0,A[2]-A[1]+1):
            str[A[1]+j]=rep[j]

Submission status: Accepted

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

for _ in range(n):
    command = input().split()
    st = int(command[1])
    en = int(command[2])

    if command[0] == "print":
        print(text[st:en+1])

    elif command[0] == "reverse":
        if st == 0:
            text = text[en::-1] + text[en+1:]
        else:
            text = text[:st] + text[en:st-1:-1] + text[en+1:]

    elif command[0] == "replace":
        text = text[:st] + command[3] + text[en+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:]