My String

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 32M

Author:
Problem type
Allowed languages
Python

Problem Statement

Design a class MyString which inherits from built-in str class In this programming problem,you need to defined two methods, __lshift__, __rshift__, for string left rotation and right rotation respectively. Note that you need to keep the original string unchanged after you do any operation.

class MyString(str):
    def __lshift__(self,val):
        #Your code here
    def __rshift__(self,val):
        #Your code here

# Note that the following code is for local testing purposes only. You should leave this part of code unchanged and not submit it to the OJ system.
T = int(input())
for i in range(1,T+1):
    s = MyString(input())
    n1,n2 = map(int,input().split())
    print(f'Case #{i}_1: After left rotate {n1} positions the string will be "{s<<n1}"')
    print(f'Case #{i}_2: After right rotate {n2} positions the string will be "{s>>n2}"')
    print(f'Case #{i}_3: The origin string: "{s}"')

Please note that you only have to submit the definition of the MyString and its content to the OJ system. The rest of the code is for your local testing purposes only.

Input Specification

The first line of the input contains a single integer T, the number of test cases.

For each test case, there are two lines:

The first line contains a string s.

The second line contains two non-negative integer n1 and n2,indicating the number of positions that you need to left rotate and right rotate respectively.

Constraints

1 \leq T \leq 100

0 \leq len(s) \leq 100

0 \leq n1,n2 \leq 10000

Output Specification

For each function call, you must return exactly what we asked for.

Sample Input

2
Hello World
5 3

10 2

Sample Output

Case #1_1: After left rotate 5 positions the string will be " WorldHello"
Case #1_2: After right rotate 3 positions the string will be "rldHello Wo"
Case #1_3: The origin string: "Hello World"
Case #2_1: After left rotate 10 positions the string will be ""
Case #2_2: After right rotate 2 positions the string will be ""
Case #2_3: The origin string: ""

Hint

object-oriented programming


Comments

There are no comments at the moment.