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:
def convert():
    str = input().rstrip()
    n = int(input().rstrip())
    
    for _ in range(n):
        columns = input().rstrip().split()
        order = columns[0]
        a = int(columns[1])
        b = int(columns[2])
        
        if order == 'print':
            print(str[a:b+1])
            
        if order == 'reverse':
            str = str[:a] + str[a:b+1][::-1] + str[b+1:]
        
        if order == 'replace':        
            p = columns[3]
            str = str[:a] + p + str[b+1:] 
if __name__ == '__main__':
    convert()

Submission status: Accepted

Solution code:
s = str(raw_input())
q = int(raw_input())
for i in range(q):
    line = map(str, raw_input().split())
    com = line[0]
    a = int(line[1])
    b = int(line[2])
    if com == "print":
        print s[a:b+1]
    elif com == "reverse":
        tmp = s[::-1]
        s = s[:a] + tmp[len(tmp)-b-1:len(tmp)-a] + s[b+1:]
    elif com == "replace":
        p = line[3]
        s = s[:a] + p + s[b+1:]
    else:
        print "Error"

Submission status: Accepted

Solution code:
sentence = input()
jobs = int(input())

def my_print(s, x, y):
    print(s[x:y+1])

def my_replace(s, x, y, t):
    s = list(s)
    s[x:y+1] = t
    return "".join(s)

def my_reverse(s, x, y):
    s = list(s)
    ss = s[x:y+1]
    ss.reverse()
    s[x:y+1] = ss
    return "".join(s)

for _ in range(jobs):
    task = input().split()
    task[1], task[2] = int(task[1]), int(task[2])
    if task[0] == "print":
        my_print(sentence, task[1], task[2])
    elif task[0] == "replace":
        sentence = my_replace(sentence, task[1], task[2], task[3])
    elif task[0] == "reverse":
        sentence = my_reverse(sentence, task[1], task[2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AOJ ITP1_9_D

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    string = input()
    n = int(input())
    for i in range(n):
        command = input().split()
        a = int(command[1])
        b = int(command[2])
        if command[0][0] == 'r':
            front = string[0 : a]
            back = string[b + 1 : len(string)]
        if command[0][2] == 'p':
            string = front + command[3] + back
        elif command[0][2] == 'v':
            string = front + string[a : b + 1][::-1] + back
        else:
            print(string[a : b + 1])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def replace(str):
    for i, c in enumerate(command[3], command[1]):
        str[i] = c
    return str

def reverse(str):
    for i, c in enumerate(reversed(str[command[1]: command[2]+1]), command[1]):
        str[i] = c
    return str

def str_print(str):
    str = ''.join(str)
    print(str[command[1]: command[2]+1])
    str = list(str)
    return str

str = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    command[1], command[2] = int(command[1]), int(command[2])
    if command[0] == 'replace':
        str = replace(str)
    elif command[0] == 'reverse':
        str = reverse(str)
    else:
        str = str_print(str)

Submission status: Accepted

Solution code:
p = input()
num = int(input())
for i in range(num):
    order = list(map(str,input().split()))
    a = int(order[1])
    b = int(order[2])
    if order[0] == 'print':
        print(p[a:b+1])
    elif order[0] == 'replace':
        rep = order[3]
        p = p[:a] + rep + p[b+1:]
    else:
        p = p[:a] + p[a:b+1][::-1] + p[b+1:]

Submission status: Accepted

Solution code:
def my_print():
    print("{}".format("".join(str[command[1]: command[2]])))

def replace():
    command[3] = list(command[3])
    str[command[1]: command[2]] = command[3]

def reverse():
    str[command[1]: command[2]] = reversed(str[command[1]: command[2]])

str = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    command[1], command[2] = int(command[1]), int(command[2]) + 1
    if command[0] == "print":
        my_print()
    elif command[0] == "replace":
        replace()
    else:
        reverse()

Submission status: Accepted

Solution code:

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

for i in range(q):
	arr = list(map(str, input().split()))
	c = arr[0]
	n1 = int(arr[1])
	n2 = int(arr[2])

	if c == 'print':
		print(s[n1:n2 + 1])
	if c == 'replace':
		s = s[0:n1] + arr[3] + s[n2 + 1:len(s)]
	if c == 'reverse':
		l = n2 - n1 + 1
		reverse = ''
		for i in range(l):
			reverse += s[n2 - i]
		s = s[0:n1] + reverse + s[n2 + 1:len(s)]

Submission status: Accepted

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

for i in range(n):
    command = input().split()
    if command[0] == 'replace':
        a,b = map(int,command[1:3])
        s = s[:a]+ command[3] + s[b+1:]
    elif command[0] == 'reverse':
        a,b = map(int,command[1:3])
        s = s[0:a] + s[a:b+1][::-1] + s[b+1:]
    elif command[0] == 'print':  
        a,b = map(int,command[1:3])
        print(s[a:b+1])

Submission status: Accepted

Solution code:
s = input()
n = int(input())
for _ in range(n):
    li = input().split()
    op = li[0]
    a, b = map(int, li[1:3])
    if op == "replace":
        p = li[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])

Submission status: Accepted

Solution code:
input_str = input()
n_orders = int(input())
for _ in range(n_orders):
    order_str = input()
    if order_str.startswith('print'):
        _, start, end = [s.strip() for s in order_str.split()]
        start = int(start)
        end = int(end) + 1
        print(input_str[start:end])
    elif order_str.startswith('reverse'):
        _, start, end = [s.strip() for s in order_str.split()]
        start = int(start)
        end = int(end) + 1
        rev_str = input_str[start:end]
        rev_str = list(reversed(rev_str))
        input_str = list(input_str)
        input_str[start:end] = rev_str
        input_str = ''.join(input_str)
    elif order_str.startswith('replace'):
        _, start, end, rep_str = [s.strip() for s in order_str.split()]
        start = int(start)
        end = int(end) + 1
        input_str = list(input_str)
        input_str[start:end] = rep_str
        input_str = ''.join(input_str)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Transformation

string = input()
commandAmount = int(input())

for i in range(commandAmount):
    command = input().rstrip().split()
    start = int(command[1])
    end = int(command[2])
    if command[0] == 'print':
        print(string[start : end + 1]) # ここはコメントアウトしないこと
    elif command[0] == 'reverse':
        replacedString = list(string)
        # print(replacedString)
        for i in range(start, end + 1):
            replacedString[i] = list(string)[start + end - i]
        # print(replacedString)
        string = ''.join(replacedString)
    elif command[0] == 'replace':
        string = list(string)
        replace = list(command[3])
        for i in range(start, end + 1):
            string[i] = replace[i - start]
        string = ''.join(string)

Submission status: Accepted

Solution code:
word = str(input())
wlist = []
for i in word:
    wlist.append(i)
n = int(input())
for i in range(n):
    com = list(input().split())
    a = int(com[1])
    b = int(com[2])
    if (com[0] == 'print'):
        for k in range(a, b + 1):
            print(wlist[k], end ='')
        print()
    elif (com[0] == 'reverse'):
        decoy = []
        for k in range(a, b+1):
            decoy.append(wlist[b+a-k])
        for l in range(b-a+1):
            wlist[a+l] = decoy[l]
    elif (com[0] == 'replace'):
        p = str(com[3])
        plist = []
        for k in p:
            plist.append(k)
        for l in range(b-a+1):
            wlist[a+l] = plist[l]

Submission status: Accepted

Solution code:
s = input()
for _ in range(int(input())):
	o = list(map(str, input().split()))
	a = int(o[1])
	b = int(o[2])
	if o[0] == "print":
		print(s[a:b+1])
	elif o[0] == "reverse":
		s = s[:a] + s[a:b+1][::-1] + s[b+1:]
	else:
		s = s[:a] + o[3] + s[b+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=input()
n=int(input())
for _ in range(n):
    tmp=list(map(str,input().split()))
    a,b=int(tmp[1]),int(tmp[2])+1
    if tmp[0]=="print":
        print(s[a:b])
    elif tmp[0]=="reverse":
        stmp=s[a:b]
        s=s[:a]+stmp[::-1]+s[b:]
    else:
        p=tmp[3]
        s=s[:a]+p+s[b:]

Submission status: Accepted

Solution code:
string=input()
q=int(input())
for i in range(q):
    lst=input().split()
    order=lst[0]
    if order=='reverse':
        a=int(lst[1])
        b=int(lst[2])
        extraction=''
        for l in range(a,b+1):
            letter=string[l]
            extraction+=letter
        oppose=extraction[::-1]
        lst=list(string)
        lst[a:b+1]=oppose
        string="".join(lst)
    if order=='replace':
        a=int(lst[1])
        b=int(lst[2])
        p=lst[3]
        move=p
        lst=list(string)
        lst[a:b+1]=move
        string="".join(lst)
    if order=='print':
        a=int(lst[1])
        b=int(lst[2])
        extraction=''
        for o in range(a,b+1):
            letter=string[o]
            extraction+=letter
        print(extraction)

Submission status: Accepted

Solution code:
st = str(input())
q = int(input())
com = []
for i in range(q):
	com.append(input().split())
for k in com:
	if k[0] == "print":
		print(st[int(k[1]):int(k[2])+1])
	elif k[0] == "reverse":
		s = list(st[int(k[1]):int(k[2])+1])
		s.reverse()
		ss = "".join(s)
		st = st[:int(k[1])] + ss + st[int(k[2])+1:]
	else:
		st = st[:int(k[1])] + k[3] + st[int(k[2])+1:]

Submission status: Accepted

Solution code:
t = input()
n = int(input())
for i in range(n):
    orders = input().split()
    order = orders[0]
    a = int(orders[1])
    b = int(orders[2])

    if order == "replace":
        word = orders[3]
        t = t[:a] + word + t[b+1:]
    if order == "print":
        print(t[a:b+1])
    if order == "reverse":
        t = t[:a] + t[a:b+1][::-1]+ t[b+1:]

Submission status: Accepted

Solution code:
s = input()
q = int(input())
#+---+---+---+---+---+---+
#| P | y | t | h | o | n |
#+---+---+---+---+---+---+
#0   1   2   3   4   5   6
#-6  -5  -4  -3  -2  -1
for i in range(0, q):
  l = list(input().split())
  a = int(l[1])
  b = int(l[2]) + 1
  if l[0] == "print":
    print(s[a: b])
  elif l[0] == "reverse":
    rev = s[a: b]
    rev = rev[::-1]
    s = s[:a] + rev + s[b:]
  else:
    s = s[:a] + l[3] + s[b:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for _ in range(q):
    query = list(input().split())
    l,r = map(int,query[1:3])
    if query[0] == 'replace':
      p = query[3]
      s = s[:l] + p + s[r+1:]
    elif query[0] == 'reverse':
      s = s[:l] + ''.join(list(reversed(s[l:r+1]))) + s[r+1:]
    else:
      print(s[l:r+1])

Submission status: Accepted

Solution code:
# coding: utf-8

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 = input()
q = int(input())
for i in range(q):
    order = list(input().split())
    o = order[0]
    a = int(order[1])
    b = int(order[2])
    
    if o=='print':
        print(Str[a:b+1])
    
    if o=='reverse':
        StrL = list(Str)
        t = list(Str[a:b+1])
        j = len(t)-1
        for i in range(a,b+1):
            StrL[i] = t[j]
            j -= 1
        Str = ''.join(StrL)
    
    if o=='replace':
        p = list(order[3])
        StrL = list(Str)
        j = 0
        for i in range(a,b+1):
            StrL[i] = p[j]
            j += 1
        Str = ''.join(StrL)

Submission status: Accepted

Solution code:
def ss_reverse(ss,a,b):
    rev = ss[a:b+1]
    rev = rev[::-1]
    edited = ss[:a] + rev + ss[b+1:]
    return edited

def ss_replace(ss,a,b,word):
    edited = ss
    edited= ss[:a] + word + ss[b+1:]
    return edited

def print_result(ss,a,b):
    print(ss[a:b+1])

ss = input()
n = int(input())

for i in range(n):
    I = input().split()
    if len(I) == 4:
        ss = ss_replace(ss,int(I[1]),int(I[2]),I[3])
    
    if I[0] == "reverse" :
        ss = ss_reverse(ss,int(I[1]),int(I[2]))

    if I[0] == "print" :
        print_result(ss,int(I[1]),int(I[2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# 9d
#

def main():
    s = input()
    q = int(input())
    for i in range(q):
        l = list(input().split())
        a = int(l[1])
        b = int(l[2])
        if l[0] == "print":
            print(s[a:b+1])
        elif l[0] == "reverse":
            s = s[0:a] + s[a:b+1:][::-1] + s[b+1:]
        elif l[0] == "replace":
            s = s[0:a] + l[3] + s[b+1:]
        else:
            pass


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

  if "replace" in c:
    s = s[:a] + c[3] + s[b+1:]
        
  if "reverse" in c:
    u = s[a:b+1]
    s = s[:a] + u[:: -1] +s[b + 1:]

  if "print" in c:
    print(s[a:b+1], sep = '')

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(n):
    command = input().split()
    a = int(command[1])
    b = int(command[2])
    if command[0] == 'print':
        print(line[a:b+1])
    if command[0] == 'reverse':
        line = line[:a] + line[a:b+1][::-1] + line[b+1:]
    if command[0] == 'replace':
        line = line[:a] + command[3] + line[b+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class String:
    def __init__(self,letter):
        self.letter=letter
        self.memory=''
    def println(self,start,end):
        print(self.letter[start:(end+1)])
    def replace(self,start,end,alt):
        self.memory=''
#         obj=self.letter[start:(end+1)]
        if(start!=0 and end!=(len(self.letter)-1)):
            self.memory=self.letter[0:start]+alt+self.letter[(end+1):]
        elif(start==0):
            self.memory=alt+self.letter[(end+1):]
        elif(end==(len(self.letter)-1)):
            self.memory=self.letter[:start]+alt
        self.letter=self.memory
#         self.letter=self.letter.replace(obj,alt)
    def reverse(self,start,end):
        self.memory=''
        if(start==0):
            obj=self.letter[end::-1]
            self.memory=obj+self.letter[(end+1):]
        else:
            obj=self.letter[end:(start-1):-1]
            self.memory=self.letter[0:start]+obj+self.letter[(end+1):]
        self.letter=self.memory
    def check(self):
        return self.letter
    
##main##
val=input()
q=int(input())
my_str=String(val)
for i in range(q):
    command=input().split()
    if(command[0]=="print"):
        my_str.println(int(command[1]),int(command[2]))
    elif(command[0]=="replace"):
        my_str.replace(int(command[1]),int(command[2]),command[3])
    elif(command[0]=="reverse"):
        my_str.reverse(int(command[1]),int(command[2]))

Submission status: Accepted

Solution code:
str = input()
lstr = list(str)

num = int(input())

for i in range(num):
    order = input().split()

    if (order[0] == "print"):
        onum = list(map(int,order[1:3]))

        for i in range(onum[0],onum[1]+1):
            print(lstr[i],end = "")
        print("")

    elif (order[0] == "reverse"):
        onum = list(map(int,order[1:3]))
        if (onum[0] == 0):
            tmp1 = lstr[0:onum[1]+1]
            tmp1.reverse()
            tmp2 = lstr[onum[1]+1:]
            lstr = tmp1 + tmp2

        else:
            tmp1 = lstr[:onum[0]]
            tmp2 = lstr[onum[0]:onum[1]+1]
            tmp2.reverse()
            tmp3 = lstr[onum[1]+1:]
            lstr = tmp1 + tmp2 +tmp3

    elif (order[0] == "replace"):
        onum = list(map(int,order[1:3]))
        restr = list(order[3])

        for i in range(onum[0],onum[1]+1):
            lstr[i] = restr[i-onum[0]]

Submission status: Accepted

Solution code:
def mapt(fn, *args):
    return list(map(fn, *args))

def Array(listseq):
    return mapt(Vector, listseq)

def Vector(line):
    return mapt(Atom, line.split(" "))

def Atom(segment):
    try:
        return int(segment)
    except ValueError:
        try:
            float(segment)
        except ValueError:
            return segment


def parse_second(rest):
    first, end, strings = rest[0], rest[1], rest[-1]
    return first, end+1, strings


def main(word, orders):
    parsed =Array(orders)
    word = list(word)
    for cmd, *rest in parsed:
        first, end, strings = parse_second(rest)

        if    cmd == "replace": word[first:end] = strings
        elif  cmd == "reverse": word[first:end] = reversed(word[first:end])
        else: print("".join(word[first:end]))



word = input()
times = int(input())
orders = [input() for _ in range(times)]
main(word, orders)

Submission status: Accepted

Solution code:
line = input()

num_query = int(input())

for loop in range(num_query):

    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:
N=input()
Z=int(input())
for i in range(Z):
    C=list(input().split())
    at=int(C[1])
    bt=int(C[2])
    if C[0]=="print":
      print(N[at:bt+1])
    elif C[0]=="replace":
      N=N[:at]+C[3]+N[bt+1:]
    else:
      re=N[at:bt+1]
      N=N[:at]+re[::-1]+N[bt+1:]

Submission status: Accepted

Solution code:
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    q1 = int(q[1])
    q2 = int(q[2]) + 1
    if q[0] == "print":
        sl = list(s)
        print("".join(sl[q1:q2]))
    elif q[0] == "reverse":
        sl = list(s)
        bb = sl[q1:q2]
        bb.reverse()
        s = "".join(sl[:q1] + bb + sl[q2:])
    elif q[0] == "replace":
        sl = list(s)
        s = "".join(sl[:q1]) + q[3] + "".join(sl[q2:])

Submission status: Accepted

Solution code:
str0=input()
q=int(input())
for i in range(q):
  ord=input()
  if "print" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    print(str0[a:b+1])
  if "replace" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    str0=str0[0:a]+buff[3]+str0[b+1:]
  if "reverse" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    tmp=str0[a:b+1]
    str0=str0[0:a]+''.join(list(reversed(tmp)))+str0[b+1:]

Submission status: Accepted

Solution code:
characters = list(input())
n = int(input())
for i in range(n):
  order_list = list(map(str, input().split()))
  order_list[1] = int(order_list[1])
  order_list[2] = int(order_list[2])
  if order_list[0] == 'replace':
    for j in range(order_list[1], order_list[2]+1):
      characters[j] = order_list[3][j-order_list[1]]
  if order_list[0] == 'reverse':
    sliced_part = characters[order_list[1]:order_list[2]+1]
    sliced_part = sliced_part[::-1]
    for j in range(order_list[1], order_list[2]+1):
      characters[j] = sliced_part[j-order_list[1]]
  if order_list[0] == 'print':
    for i in range(order_list[1], order_list[2]+1):
      print(characters[i], end='')
    print('')

Submission status: Accepted

Solution code:
def print_ab(sent, a, b):
    res = sent[a:b + 1]
    return res

def reverse_ab(sent, a, b):
    top = sent[:a]
    las = sent[b+1:]
    tag = sent[a:b+1]
    n = len(tag)
    rev = ""
    for i in range(n):
        rev = rev + tag[n - i - 1]
    rev = top + rev + las
    return rev

def replace_abp(sent, a, b, p):
    top = sent[:a]
    las = sent[b+1:]
    rep = top + p + las
    return rep

#print(print_ab("xyz", 0, 2))
#print(reverse_ab("abcde", 1, 3))
#print(replace_abp("xyz", 0, 2, "abc"))

sent = input()
op = int(input())
results = []
for i in range(op):
    oder = list(map(str, input().split()))
    if oder[0] == "print":
        res = print_ab(sent, int(oder[1]), int(oder[2]))
        results.append(res)
    elif oder[0] == "reverse":
        sent = reverse_ab(sent, int(oder[1]), int(oder[2]))
    else:
        sent = replace_abp(sent, int(oder[1]), int(oder[2]), oder[3])

for s in results:
    print(s)

Submission status: Accepted

Solution code:
s = input()
n = int(input())
for _ in range(n):
    O = list(map(str, input().split()))
    i = int(O[1])
    j = int(O[2])
    if O[0] == 'print':
        print(s[i:j + 1])
    elif O[0] == 'reverse':
        ss = s[i:j + 1]
        s = s[:i] + ss[::-1] + s[j + 1:]
    else:
        p = O[3]
        s = s[:i] + p + s[j + 1:]

Submission status: Accepted

Solution code:
a=input()
b=int(input())
while b>0:
    tmp=input().split(" ")
    if tmp[0]=="replace":
        a=a[:int(tmp[1])]+tmp[3]+a[int(tmp[2])+1:]
    if tmp[0]=="reverse":
        tmp2="".join(list(a)[int(tmp[1]):int(tmp[2])+1])[::-1]
        a=a[:int(tmp[1])]+tmp2+a[int(tmp[2])+1:]
    if tmp[0]=="print":
        print(a[int(tmp[1]):int(tmp[2])+1])
    b-=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 9_A
# w = input().upper()
# t = ""
# while True:
#     tmp = input()
#     if tmp == "END_OF_TEXT":
#         break
#     t += tmp.upper() + " "
# list = t.split()
# print(list.count(w))

# 9_B
# while True:
#     t = input()
#     if t == "-":
#         break
#     m = int(input())
#     for i in range(m):
#         h = int(input())
#         t = t[h:] + t[:h]
#     print(t)

# 9_C
# n = int(input())
# score_t, score_h = 0, 0
# for i in range(n):
#     t, h = input().split()
#     if t > h:
#         score_t += 3
#     elif h > t:
#         score_h += 3
#     else:
#         score_t += 1
#         score_h += 1
# print(f"{score_t} {score_h}")

# 9_D
t = str(input())
o_list = []
for i in range(int(input())):
    o_list = input().split()
    a, b = int(o_list[1]), int(o_list[2])
    if o_list[0] == "print":
        print(t[a : b + 1])
    elif o_list[0] == "reverse":
        t = t[:a] + t[a : b + 1][::-1] + t[b + 1 :]
    elif o_list[0] == "replace":
        t = t[:a] + o_list[3] + t[b + 1 :]

Submission status: Accepted

Solution code:
a=input()
a=list(a)
b=int(input())
c=[]
for i in range(b):
    c.append(input().split())
    x=int(c[i][1])
    y=int(c[i][2])
    if c[i][0]=="replace":
        a[x:y+1]=c[i][3]
    elif c[i][0]=="reverse":
        z=a[x:y+1]
        z.reverse()
        a[x:y+1]=z
    else:
        w=a[x:y+1]
        print("".join(w))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

def reverse(s, i, j):
    tmp = ''
    for i in range(j, i-1, -1):
        tmp += s[i]
    return s[:i] + tmp + s[j+1:]

def pprint(s, i, j):
    print(s[i:j+1])

def replace(s, i, j, r):
    tmp = s[:i] + r + s[j+1:]
    return tmp

word = input()
# word = 'abcde'
loop = int(input())
# loop = 3
# arr = [
#     'replace 1 3 xyz',
#     'reverse 0 2',
#     'print 1 4',
#     ]

for i in range(loop):
    line = input().split()
    # line = arr[i].split()
    # print(word)
    if line[0] == 'replace':
        word = replace(word, int(line[1]), int(line[2]),line[3])
    elif line[0] == 'reverse':
        word = reverse(word, int(line[1]), int(line[2]))
    elif line[0] == 'print':
        pprint(word, int(line[1]), int(line[2]))

Submission status: Accepted

Solution code:
s=str(input())
n=int(input())
for i in range(n):
    a=list(input().split())
    x=int(a[1])
    y=int(a[2])
    if a[0]=="print":
        print(s[x:y+1])
    elif a[0]=="replace":
        c=a[3]
        s=s[0:x]+c+s[y+1:]
    elif a[0]=="reverse":
        s=s[:x]+s[x:y+1][::-1]+s[y+1:]

Submission status: Accepted

Solution code:
string = str(input())
q = int(input())
for _ in range(q):
    
    data = input().split()
    left = int(data[1])
    right = int(data[2]) + 1
    
    if data[0] == "print":
        print(string[left:right])
        
    elif data[0] == "reverse":
        string = string[:left] + string[left:right][::-1] + string[right:]
        
    else:
        string = string[:left] + data[3] + string[right:]

Submission status: Accepted

Solution code:
string = list(input())
n = int(input())

for repeat in range(n):
    ope = input().split()

    if ope[0] == "replace":
        rep_str = list(ope[3])
        rep_ind = 0
        #print(rep_str)
        for i in range(int(ope[1]), int(ope[2])+1):
            #print(string[i],rep_str[rep_ind])
            string[i] = rep_str[rep_ind]
            rep_ind += 1
        #print(string)
        
    elif ope[0] == "reverse":
        rev_str = []
        rev_ind = int(ope[2])
        times = 0
        for i in range(len(string)):
            rev_str.append(string[i])
        for i in range(int(ope[1]),int(ope[2])+1):
            string[i] = rev_str[rev_ind]
            rev_ind -= 1
        
    elif ope[0] == "print":
        for i in range(int(ope[1]),int(ope[2])+1):
            print(string[i],end="")
        print("")

Submission status: Accepted

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

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

  if command[0]=='reverse':
    a=int(command[1])
    b=int(command[2])
    s_list=list(reversed(s[a:b+1]))
    s=s[:a]+''.join(s_list)+s[b+1:]

  if command[0]=='replace':
    a=int(command[1])
    b=int(command[2])
    p=command[3]
    s=s[:a]+p+s[b+1:]

  if command[0]=='print':
    a=int(command[1])
    b=int(command[2])
    print(s[a:b+1])

Submission status: Accepted

Solution code:
s=input()
times=int(input())
for _ in range(times):
    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[:a]+s[a:b+1][::-1]+s[b+1:]
    else :
        s=s[:a]+order[3]+s[b+1:]

Submission status: Accepted

Solution code:
string = input()
num = int(input())
orders = [input().split() for _ in range(num)]

for order in orders:
    start = int(order[1])
    end = int(order[2]) + 1
    if order[0] == "reverse":
        string = string[:start] + string[start:end][::-1] + string[end:]
    elif order[0] == "replace":
        string = string[:start] + order[3] + string[end:]
    elif order[0] == "print":
        print(string[start:end])

Submission status: Accepted

Solution code:
def my_print(s: str, args: [int]) -> str:
    return s[int(args[0]): int(args[1]) + 1]


def my_reverse(s: str, args: list) -> str:
    start = int(args[0])
    end = int(args[1]) + 1
    to_reverse_string = s[start:end]
    return s[:start] + to_reverse_string[::-1] + s[end:]


def my_replace(s: str, args: list) -> str:
    start = int(args[0])
    end = int(args[1]) + 1
    return s[:start] + args[2] + s[end:]


def resolve():
    s = input()
    n = int(input())

    for _ in range(n):
        f, *args = input().split()

        if f == 'print':
            print(my_print(s, args))
        if f == 'reverse':
            s = my_reverse(s, args)
        if f == 'replace':
            s = my_replace(s, args)


resolve()