1 String rotate left

Rotate Left String 1 (10.)
Title Contents:

Given a string S, it is required to move the first k characters of S to the end of S, such as moving the two characters 'a' and 'b' in front of the string "abcdef" to the end of the string to get the new character The string "cdefab" is called a character string rotated by k bits to the left.

Enter a character string and a non-negative integer N, and it is required to rotate the character string left N times.

You can use the following statement to achieve the input of the string s:

s=str(input())

You can use the following statement to achieve the input of a non-negative integer n:

n=int(input())

Input format:

Enter a non-empty character string that ends with a carriage return that is no more than 100 characters long on line 1; a non-negative integer N is given on line 2.

Output format:

The character string after shifting to the left N times is output in one line.

Sample input:

abcd

2

Sample output:

cdab

Time limit: 500ms Memory limit: 32000kb

my own:

s=str(input())
n=int(input())
k=s[0:n]
kk=s[n:]
out=str(kk+k)
print(out)

2.0:

s=str(input())
n=int(input())
print(s[n:]+s[:n])
Published 5 original articles · Likes0 · Visits 38

Guess you like

Origin blog.csdn.net/bb_soma/article/details/105569925