#C6374. String Rotation
String Rotation
String Rotation
You are given a string s and an integer n. Your task is to rotate the string in a circular fashion. If n is positive, rotate the string to the right n times; if n is negative, rotate the string to the left |n| times. The effective number of rotations is computed as \( n \mod |s| \), where \(|s|\) is the length of the string.
For example:
- For
s = "hello"
andn = 2
, the rotated string islohel
. - For
s = "abcdef"
andn = -3
, the rotated string isdefabc
.
Implement a program that reads the string and the integer from standard input and prints the rotated string to standard output.
inputFormat
The input consists of two lines:
- The first line contains the string
s
. - The second line contains an integer
n
, indicating the number of rotations. A positiven
indicates a right rotation, and a negativen
indicates a left rotation.
outputFormat
Output the rotated string to standard output.
## samplehello
2
lohel