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 = list(str(input()))
q = int(input())
o = ['']*q
for i in range(q):
    o[i] = str(input())
    
for i in range(q):
    order = o[i].split(' ')
    if order[0] == 'print':
        a,b = int(order[1]),int(order[2])
        for i in range(a,b+1):
            print(s[i],end = '')
        print('')

    elif order[0] == 'reverse':
        a,b = int(order[1]),int(order[2])
        tmp = s[a:b+1]
        tmp.reverse()
        s[a:b+1] = tmp        
        
    elif order[0] == 'replace':
        a,b,p = int(order[1]),int(order[2]),list(order[3])
        for i in range(b-a+1):
            s[a+i] = p[i]

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
'''
ITP-1_9-D
 ???????????????
????????? strstr ?????????????????????????????????????????????????????????????????°???????????????????????????????????????????????\?????????????????????????????§??????
print a b: strstr ??? a ??????????????? b ??????????????§??????????????????
reverse a b: strstr ??? a ??????????????? b ??????????????§?????????????????????
replace a b p: strstr ??? a ??????????????? b ??????????????§??? p ?????????????????????
????????§??????????????? strstr ????????????????????? 0 ???????????¨????????????
???Input
1 ?????????????????? strstr ????????????????????????strstr ?????±?°????????????????????????????2 ????????????????????° qq ????????????????????????
?¶???? qq ??????????????????????¨??????¢?????§?????????????????????
???Output
??? print ???????????¨???????????????????????????????????????????????????
'''
# inputData
string = input()
exeCnt = int(input())

for cnt0 in range(exeCnt):
    exeData = input().split()
    exe00 = exeData[0]
    exe01 = int(exeData[1])
    exe02 = int(exeData[2])
#    exe03 = exeData[3]

    if exe00 == 'print':
        print(string[exe01:exe02 + 1])

    elif exe00 == 'reverse':
        string = string[0:exe01] + string[exe01:exe02 + 1][::-1] + string[exe02 + 1:]

    elif exe00 == 'replace':
        exe03 = exeData[3]
        string = string[0:exe01] + exe03 + string[exe02 + 1:]

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for i in range(q):
    inp = input().split()
    order = inp[0]
    params = inp[1:]
    if order == "print":
        a,b = map(int,params)
        print(s[a:b+1])
    elif order == "reverse":
        a,b = map(int,params)
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif order == "replace":
        a,b,p = params
        a = int(a)
        b = int(b)
        s = s[:a] + p  + s[b+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def reverse(str, a, b):
	head = str[0:a]
	tail = str[b + 1:]
	mid = str[a:b + 1]
	reversed_str = head + mid[::-1] + tail
	return reversed_str

def replace(str, a, b, rstr):
	head = str[0:a]
	tail = str[b + 1:]
	replaced_str = head + rstr + tail
	return replaced_str


#fin = open("test.txt", "r")
fin = sys.stdin

str = fin.readline()
q = int(fin.readline())

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

	if op == "print":
		print(str[a:b + 1])
	elif op == "reverse":
		str = reverse(str, a, b)
	else:
		str = replace(str, a, b, query_list[3])

Submission status: Accepted

Solution code:
#!usr/bin/env python3

import sys


def main():
    s = sys.stdin.readline().strip('\n')
    q = int(sys.stdin.readline().strip('\n'))

    for instruction in range(q):
        words = [word for word in sys.stdin.readline().strip('\n').split()]
        if words[0] == 'replace':
            s = s[:int(words[1])] + words[3] + s[int(words[2])+1:]
        elif words[0] == 'reverse':
            s = s[:int(words[1])] \
                    + ''.join(reversed(s[int(words[1]):int(words[2])+1])) \
                    + s[int(words[2])+1:]
        elif words[0] == 'print':
            print(s[int(words[1]):int(words[2])+1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(q):
	L = input().split()
	a = int(L[1])
	b = int(L[2])
	slice1 = S[:a]
	slice2 = S[a:b+1]
	slice3 = S[b+1:]
	if L[0] == 'print':
		print(slice2)
	elif L[0] == 'reverse':
		S = slice1 + slice2[::-1] + slice3
	elif L[0] == 'replace':
		S = slice1 + L[3] + slice3

Submission status: Accepted

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

Submission status: Accepted

Solution code:
word=''
com = ""
a = 0
b = 0
word=str(raw_input())
num=int(raw_input())
for i in range(num):
    add= raw_input().split()
    com = add[0]
    a = int(add[1])
    b = int(add[2])
    if com == 'replace':
        word = word[0:a] + add[3] + word[b+1:]
       # word = word.replace(word[a:b+1],add[3])
    elif com == 'reverse':
        tmp = word[a:b+1]
        word = word[0:a] + tmp[::-1] + word[b+1:]
    elif com == 'print':
        print word[a:b+1]
    else :
        break

Submission status: Accepted

Solution code:
#1st line
input_str = input().strip()

#2nd line
command_max_times = int(input().strip())
command_cnt = 0

while command_cnt < command_max_times:
    command_cnt = command_cnt + 1
    input_line = input().strip().split(" ")
    
    input_command = input_line[0]
    input_sta = int(input_line[1])
    input_end = int(input_line[2])
    
    if input_command == "print":
        print(input_str[input_sta:input_end+1])
    elif input_command == "replace":
        str_replace = input_line[3]
        input_str = input_str[:input_sta] + str_replace + input_str[input_end+1:]
    elif input_command == "reverse":
        str_temp = input_str[input_sta:input_end+1]
        input_str = input_str[:input_sta] + str_temp[::-1] + input_str[input_end+1:]

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(line):
    param = input().split(" ")

    if len(param) == 4: ope, a, b, p = param
    else: ope, a, b = param

    a,b = int(a), int(b)

    if ope == "print":
        print(s[a:b+1])
    elif ope == "reverse":
        rev = s[a:b+1][::-1]
        s = (s[:a] + rev + s[b+1:])
    elif ope == "replace":
        s = (s[:a] + p + s[b+1:])

Submission status: Accepted

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

for i in range(q):
	order = [str(x) for x in input().split()]
	if order[0] == 'replace':
		str1[int(order[1]):int(order[2])+1] = list(order[3]) 
		#print(str1)
	elif order[0] == 'reverse':
		str2 = str1[int(order[1]):int(order[2])+1]
		str1[int(order[1]):int(order[2])+1] = reversed(str2)
			
	else: #print
		print(*str1[int(order[1]):int(order[2])+1], sep='')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line = input()
n = int(input())
array = [[i for i in input().split()] for i in range(n)]
for i in range(n):
    if array[i][0] == "print":
        print(line[int(array[i][1]):int(array[i][2])+1])
    elif array[i][0] == "reverse":
        if array[i][1] !="0":
            reline = line[int(array[i][2]):int(array[i][1])-1:-1]
        else:
            reline = line[int(array[i][2])::-1]
        revara = list(line)
        for i2 in range(len(reline)):
            revara[int(array[i][1])+i2] = reline[i2]
        for i2 in range(len(revara)):
            if i2 ==0:
                line = revara[i2]
            else:
                line += revara[i2]
        
    elif array[i][0] == "replace":
        repara = list(line)
        inpara = list(array[i][3])
        for i2 in range(len(inpara)):
            repara[int(array[i][1])+i2] = inpara[i2]
        for i2 in range(len(repara)):
            if i2 ==0:
                line = repara[i2]
            else:
                line += repara[i2]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
tes = input()
for mak in range(int(input())) :
    ins = input().split()
    ins[1], ins[2] = int(ins[1]), int(ins[2])
    if ins[0] == 'replace' :
        tes = tes[ : (ins[1])] + ins[3] + tes[(ins[2] + 1) :]
    elif ins[0] == 'reverse' :
        tem = tes[ins[1] : ins[2] + 1]
        tem = tem[::-1]
        tes = tes.replace(tes[ins[1] : ins[2] + 1], tem)
    elif ins[0] == 'print' :
        print(tes[ins[1] : ins[2] + 1])

Submission status: Accepted

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

for i in range(times):
    function = input().split()
    word = text[int(function[1]):int(function[2])+1]

    if function[0] == "print":
        print(word)

    elif function[0] == "reverse":
        word_reverse = word[::-1]
        text = text[:int(function[1])] + word_reverse + text[int(function[2])+1:]

    elif function[0] == "replace":
        text = text[:int(function[1])] + function[3] + text[int(function[2])+1:]

Submission status: Accepted

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

import sys
import os


s = input().strip()
N = int(input())
for i in range(N):
    lst = input().split()
    command = lst[0]
    if command == 'replace':
        a = int(lst[1])
        b = int(lst[2])
        p = lst[3]
        s = s[:a] + p + s[b+1:]
    elif command == 'reverse':
        a = int(lst[1])
        b = int(lst[2])
        part = s[a:b+1]
        part = part[::-1]
        s = s[:a] + part + s[b+1:]
    elif command == 'print':
        a = int(lst[1])
        b = int(lst[2])
        print(s[a:b+1])
    else:
        print('error')
    #print('s', s)

Submission status: Accepted

Solution code:
ord_list = []
str_in = input()
n = int(input())

for i in range(n):
    try:
        l = list(map(str,input().split()))
    except ValueError:
        l = list(map(str,input().split()))
    ord_list.append(l)

for l in ord_list:
    o = l[0]
    a,b = int(l[1]), int(l[2])
    if o == 'replace':
        str_in= str_in[:a] + l[3] + str_in[b+1:]
    elif o == 'reverse':
        str_in= str_in[:a] + str_in[a:b+1][::-1] + str_in[b+1:]
    elif o == 'print':
        print(str_in[a:b+1])

Submission status: Accepted

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

def reverse_ab(s, a, b):
    s_f = s[:a]
    s_m = s[a:b+1]
    s_l = s[b+1:]
    return s_f+s_m[::-1]+s_l
def replace_ab(s, a, b, p):
    s_f = s[:a]
    s_l = s[b+1:]
    return s_f+p+s_l

s = input()
q = int(input())
for i in range(q):
    option = input().split()
    if option[0] == "print":
        print_ab(s,int(option[1]),int(option[2]))
    elif option[0] == "reverse":
        s = reverse_ab(s, int(option[1]), int(option[2]))
    elif option[0] == "replace":
        s = replace_ab(s, int(option[1]), int(option[2]), option[3])

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_D

def reverse(s, a, b):
    s1 = s[0:a]
    s2 = s[a:b+1]
    s2 = s2[::-1]
    s3 = s[b+1:len(string)]
    return s1 + s2 + s3
def replace(s, a, b, p):
    s1 = s[0:a]
    s2 = p
    s3 = s[b+1:len(string)]
    return s1 + s2 + s3

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

for _ in range(q):
    c = input().split()

    if c[0] == "print":
        print(string[int(c[1]):int(c[2])+1])
    if c[0] == "reverse":
        string = reverse(string, int(c[1]), int(c[2]))
    if c[0] == "replace":
        string = replace(string, int(c[1]), int(c[2]), c[3])

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

def operate_string():

    (method, i_first, i_last, str_new) = ("method", "i_first", "i_last", "replace string")

    #load data
    operations = []
    try:
        string = input().rstrip()
        _ = input()
        while(True):
            line = input().rstrip().split()
            operations.append({method : line[0], i_first : int(line[1]), i_last : int(line[2])})
            if len(line) > 3 :
                operations[-1].update({str_new : line[3]})
    except EOFError:
        pass
    except:
        return __inputError()

    #operate string
    for ope in operations:
        if ope[method] == "print" :
            print(string[ope[i_first]:ope[i_last]+1])
        elif ope[method] == "reverse" :
            string = reverse_string_by_index (string, ope[i_first], ope[i_last])
        elif ope[method] == "replace" :
            string = replace_string_by_index (string, ope[str_new], ope[i_first], ope[i_last])
        else :
            return __inputError()


def replace_string_by_index (str_raw, str_new, i_first, i_last):
    pre_post_info = __set_pre_post_string(str_raw, i_first, i_last)
    if pre_post_info["invalid index"] :
        return str_raw

    return pre_post_info["pre"] + str_new + pre_post_info["post"]

def reverse_string_by_index (str_raw, i_first, i_last):
    pre_post_info = __set_pre_post_string(str_raw, i_first, i_last)
    if pre_post_info["invalid index"] :
        return str_raw

    str_reversed = str_raw[i_last:i_first-1:-1]
    if i_first == 0 :
        str_reversed = str_raw[i_last::-1]

    return pre_post_info["pre"] + str_reversed + pre_post_info["post"]

def __set_pre_post_string (str_raw, i_first, i_last):

    info = {"pre" : "", "post" : "", "invalid index" : False}
    info["pre"]  = str_raw[:i_first]
    info["post"] = "" if (i_last == -1) else str_raw[i_last+1:]
    info["invalid index"] = ( len(info["pre"]) + len(info["post"]) >= len(str_raw) )
    
    return info

def __inputError():
    print("input Error")
    return -1

def __Test_reverse_string_by_index (lists):
    #list[index] = [str_raw, i_first, i_last]
    for item in lists:
        print(reverse_string_by_index(item[0], item[1], item[2]))

def __Test_replace_string_by_index (lists):
    #list[index] = [str_raw, str_new, i_first, i_last]
    for item in lists:
        print(replace_string_by_index(item[0], item[1], item[2], item[3]))


#test
if __name__ == "__main__" :
    
    operate_string()
    
    '''
    __Test_replace_string_by_index ([ ["abc","A",0,1], ["abc","A",-5,-1], ["abc","",1,1], ["","A",0,0],      ["abc","A",5,6] ])
    #expected results:                 "Ac",            "A",               "ac",           ""(string error),  "abc"(index error)
    
    __Test_reverse_string_by_index ([ ["abc",0,2], ["abc",-5,-1], ["abc",3,3] ])
    #expected results:                 "cba",       "cba",         "abc"(index error)
    '''

Submission status: Accepted

Solution code:
def print_func(s, order):
    print(s[order[1]:order[2]+1])


def reverse_func(s, order):
    ans = list(s[order[1]:order[2]+1])
    ans.reverse()
    s = s[:order[1]]+''.join(ans)+s[order[2]+1:]
    return s


def replace_func(s, order):
    cnt = 0
    s = list(s)
    for i in range(order[1], order[2]+1):
        s[i] = str(order[3])[cnt]
        cnt += 1
    s = ''.join(s)
    return s


if __name__ == '__main__':
    s = input()
    for i in range(int(input())):
        order = input().split()
        order[1] = int(order[1])
        order[2] = int(order[2])
        if order[0] == 'print':
            print_func(s, order)
        elif order[0] == 'reverse':
            s = reverse_func(s, order)
        else:
            s = replace_func(s, order)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

string = input()

n = int(input())

for i in range(n):
    command = input().split()
    if "replace" in command:
        string = string[:int(command[1])] + command[3] + string[int(command[2]) + 1:]
    elif "reverse" in command:
        toReverse = string[int(command[1]):int(command[2]) + 1]
        theReverse = ""
        for i in range(len(toReverse)):
            theReverse += toReverse[-(i + 1)]
        string = string[:int(command[1])] + theReverse + string[int(command[2]) + 1:]
    else:
        print(string[int(command[1]):int(command[2]) + 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    class MyClass:
        def __init__(self):
            self.strings = ""

        def rpl(self, int1, int2, str1):
            self.strings = self.strings[:int1] + str1 + self.strings[int2+1:]

        def rvr(self, int1, int2):
            if int1 >= 1:
                revstr = self.strings[int2:int1-1:-1]
            else:
                revstr = self.strings[int2::-1]
            self.strings = self.strings[:int1] + revstr + self.strings[int2+1:]

        def pri(self, int1, int2):
            print(self.strings[int1:int2+1])

    cls = MyClass()
    cls.strings = input()
    n = int(input())
    for _ in range(n):
        li = input().split()
        if li[0] == "replace":
            cls.rpl(int(li[1]), int(li[2]), li[3])
        elif li[0] == "reverse":
            cls.rvr(int(li[1]), int(li[2]))
        elif li[0] == "print":
            cls.pri(int(li[1]), int(li[2]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    for i in range(n):
        cmds = input().split(' ')

        if 'reverse' == cmds[0]:
            a = int(cmds[1])
            b = int(cmds[2])+1

            s = s[:a]+''.join(reversed(s[a:b]))+s[b:]

        if 'replace' == cmds[0]:
            a = int(cmds[1])
            b = int(cmds[2])+1
            res = cmds[3]

            s = s[:a]+res+s[b:]

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

            print(s[a:b])

if __name__ == '__main__': main()

Submission status: Accepted

Solution code:
def sprint(str, a, b):
 print(str[a:b+1])

def reverse(str, a, b):
 str1 = str[:a]
 str2 = str[a: b+1]
 str3 = str[b+1:]
 str = str1 + str2[::-1] + str3
 return str

def replace(str, a, b, p):
 str1 = str[:a]
 str3 = str[b+1:]
 str = str1 + p + str3
 return str

str = input()
q = int(input())
for i in range(q):
 L = input().split()
 if L[0] == "replace":
  str = replace(str, int(L[1]), int(L[2]), L[3])
 if L[0] == "reverse":
  str = reverse(str, int(L[1]), int(L[2]))
 if L[0] == "print":
  sprint(str, int(L[1]), int(L[2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
q = int(input())
for i in range(q):
    cmd = list(input().split())
    m = int(cmd[1])
    n = int(cmd[2])
    if cmd[0] == "print":
        for i in range(m, n + 1):
            print(s[i], end="")
        print()

    if cmd[0] == "reverse":
        half = int((n - m) / 2)
        while m <= half\
        or    m < n:
            t = s[m]
            s[m] = s[n]
            s[n] = t
            m += 1 
            n -= 1
    if cmd[0] == "replace":
        r = cmd[3]
        j = 0
        for i in range(m, n + 1):
            s[i] = r[j]
            j += 1

Submission status: Accepted

Solution code:
s = list(input())
n = int(input())
for i in range(n):
    d = input().split(" ")
    if d[0] == "replace":
        a = int(d[1])
        b = int(d[2])
        c = list(d[3])
        k = 0
        for j in range(a, b+1):
            s[j] = c[k]
            k += 1
    elif d[0] == "reverse":
        a = int(d[1])
        b = int(d[2])
        c = list(s)
        k = b
        for j in range(a, b+1):
            s[j] = c[k]
            k -= 1
    else:
        a = int(d[1])
        b = int(d[2])
        for j in range(a, b+1):
            print(s[j],end="")
        print("")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
q = int(input())
for i in range(q):
    cmd = [s for s in input().split()]
    cmd[1] = int(cmd[1])
    cmd[2] = int(cmd[2])
    if cmd[0] == "replace":
        c = list(cmd[3])
        h = 0
        for j in range(cmd[1], cmd[2]+1):
            s[j] = c[h]
            h+=1
    elif cmd[0] == "reverse":
        k = cmd[1]
        l = cmd[2]
        while k < l:
            t = s[k]
            s[k] = s[l]
            s[l] = t
            k+=1
            l-=1
    else:
        for m in range(cmd[1], cmd[2]+1):
            print("{}".format(s[m]), end = "")

        print()

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(q):
    ops = input().split()

    if len(ops) == 3:
        op, a, b = ops
    else:
        op, a, b, p = ops

    a = int(a)
    b = int(b)

    if op == 'print':
        print(text[a:b+1])
    elif op == 'reverse':
        text = text[:a] + ''.join(reversed(text[a:b+1])) + text[b + 1:]
    else:
        text = text[:a] + p + text[b + 1:]

Submission status: Accepted

Solution code:
sen = input()
n = int(input())
for i in range(n):
    cmd = input().split()
    sta = int(cmd[1])
    end = int(cmd[2])
    if cmd[0] == 'replace':
        sen = sen[0:sta] + cmd[3] + sen[end+1:]
    elif cmd[0] == 'reverse':
        rev = sen[sta:end+1]
        rev = rev[::-1]
        # print(rev)
        sen = sen[0:sta] + rev +sen[end+1:]
    elif cmd[0] == 'print':
        print(sen[sta:end+1])
    # print('sen : '+sen)

Submission status: Accepted

Solution code:
x=[i for i in input()]
y=[i for i in range(len(x))]
y=x.copy()
n=int(input())
for i in range(n):
    c=[j for j in input().split()]
    if len(c)==4:
        for j in range(len(c[3])):
            y[j+int(c[1])]=list(c[3])[j]
        x=y.copy()
    elif c[0]=="print":
        for j in range(int(c[1]),int(c[2])+1):
            print(x[j],end="")
        print()
    else:
        for j in range(int(c[2])+1-int(c[1])):
            z=[i for i in range(len(x))]
            z=x.copy()
            y[int(c[2])-j]=z[int(c[1])+j]
        x=y.copy()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????????
"""
inputstr = input().strip()
cmdnum = int(input().strip())

for i in range(cmdnum) :
    cmd = input().strip().split()

    if cmd[0] == "print":
        start = int(cmd[1])
        end = int(cmd[2]) + 1
        print(inputstr[start:end])

    if cmd[0] == "reverse":
        start = int(cmd[1])
        end = int(cmd[2]) + 1
        prev = inputstr[:start]
        revr = inputstr[start:end]
        next = inputstr[end:]
        inputstr = prev + revr[::-1] + next

    if cmd[0] == "replace":
        start = int(cmd[1])
        end = int(cmd[2]) + 1
        inputstr = inputstr[:start] + cmd[3] + inputstr[end:]

Submission status: Accepted

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

def f2(s,a,b):
	temp = s[a:b+1]
	return s[:a] + temp[::-1] + s[b+1:]

def f3(s,a,b,p):
	return s[:a] + p + s[b+1:]

data = input()
q = int(input())
functions = {'print':f1, 'reverse':f2, 'replace':f3}

for i in range(q):
	temp = [s if s.isalpha() else int(s) for s in input().split(' ')]
	f = temp.pop(0)
	data = functions[f](data,*temp)

Submission status: Accepted

Solution code:
def main():
    STR = input()
    Q = int(input())
    ORDER = tuple(tuple(input().split()) for _ in range(Q))

    str_ = list(STR)
    for order in ORDER:
        s = int(order[1])
        e = int(order[2]) + 1
        a = str_[s:e]
        if order[0] == 'print':
            print(''.join(a))
        elif order[0] == 'reverse':
            a = a[::-1]
            j = s
            for i in range(s, e):
                str_[i] = a[i-j]
        elif order[0] == 'replace':
            j = s
            for i in range(s, e):
                str_[i] = order[3][i-j]

main()

Submission status: Accepted

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

for i in range(q):
    cmd=list(input().split())
    
    if cmd[0]=="replace":
        s[int(cmd[1]):int(cmd[2])+1]=cmd[3]
        
    if cmd[0]=="reverse":
        ts=s[int(cmd[1]):int(cmd[2])+1]
        ts.reverse()
        s[int(cmd[1]):int(cmd[2])+1]=ts
        
    if cmd[0]=="print":
        ts=s[int(cmd[1]):int(cmd[2])+1]
        print("".join(ts))

Submission status: Accepted

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

for i in range(cnt):
    linearr = (input().split())
    cmd = linearr[0]
    a = int(linearr[1])
    b = int(linearr[2])

    if cmd == "print":
        print(string[a:b+1])
    elif cmd == "replace":
        string = string[:a] + linearr[3] + string[b + 1:]
    elif cmd == "reverse":
        string = string[:a] + string[a:b + 1][::-1] + string[b + 1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str_1=input()
q=int(input())
for _ in range(q):
   lst=list(input().split())
   res = (lst[0])
   a = int(lst[1])
   b = int(lst[2])+1
  
   if res=='print':
     print(str_1[a:b])
   elif res=='replace':
    str_1=str_1[:a]+lst[3]+str_1[b:]
   elif res=='reverse':
    str_1=str_1[:a] + str_1[a:b][::-1] + str_1[b:]

Submission status: Accepted

Solution code:
z = input()
s = int(input())
b, c = 0,0
r=[]
for i in range(s):
    a = input().split()
    if a[0] == "print":
        b, c = int(a[1]), int(a[2])
        print(z[int(b):int(c)+1])
    elif a[0] == "reverse":
        b, c = int(a[1]), int(a[2])
        r= list(z[b:c+1])
        r=r[::-1]
        z=list(z)
        z[b:c+1]=r
        z=''.join(z)

    else:
        b, c, d = int(a[1]), int(a[2]), list(a[3])
        z=list(z)
        z[b:c+1]=d
        z=''.join(z)