Rotate the String

View as PDF

Submit solution


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

Authors:
Problem type
Allowed languages
Python

Problem Statement

You are given a string S and an integer R. Your task is to rotate the string S to the left by R positions and return the result. If R is negative, you should rotate the string to the right by the absolute value of R positions and return the result.

Input Specification

The first line of the input gives the number of test cases, T, T test cases follow. Each test case consists of two lines. The first line contains a string S.

The second line contains a integer R, representing the number of positions you need to rotate.

Limits

Memory limits: 32MB.

Time limits: 1 second.

1 \leq T \leq 100

0 \leq \text{length of }S \leq 50

-100 \leq R \leq 100

Test Set 1

Sample Case

Test Set 2

0 \leq \text{length of }S \leq 50

0 \leq R \leq \text{length of S}

Test Set 3

0 \leq \text{length of }S \leq 50

-\text{length of }S \leq R \leq \text{length of }S

Test Set 4

0 \leq \text{length of }S \leq 50

-100 \leq R \leq 100

Output Specification

For each test case, output one line containing Case #x: y, where x is the case number(starting from 1) and y is the result of rotating S by R positions.

Sample Input

2
Hello World
2
Python
1

Sample Output

Case #1: llo WorldHe
Case #2: ythonP

Hint

slice operator


Comments

There are no comments at the moment.