#C103. Rotate String Left
Rotate String Left
Rotate String Left
You are given a string s
and an integer n
. Your task is to rotate the string to the left by n
characters.
The left rotation operation moves the first n
characters of the string to the end. For example, rotating "hello" by 2 positions will yield "llohe".
If n
is greater than or equal to the length of the string, perform the rotation using modular arithmetic to determine the effective rotation, i.e., \( n \mod |s| \).
Note: If the string is empty or n
is less than or equal to 0, return the original string as is.
inputFormat
The input is provided via stdin and consists of two lines:
- The first line contains the string
s
. - The second line contains the integer
n
, denoting the number of positions to rotate.
outputFormat
The output should be printed to stdout and is a single string which is the result of rotating the input string to the left by n
characters.
hello
2
llohe