title Source: Cattle and Guest Network
for a string, design an algorithm that will have the length of the stringLenthe prefix is translated to the end of the string.
given a stringAand its length, given at the same timeLen, please return the translated string.
Test Examples:
"ABCDE", 5,3
return:"DEABC"
Python implementation
Code
def forwardmove (alist): #平移一个单位 first = alist[0] for i in Xrange (Len (alist)-1): alist[i] = alist[i+1] A List[-1] = FirstClass translation:def stringtranslation (self, A, N, Len): # write code here Alist = List (A) for I in Xrange (len): Forwardmove (alist) return '. Join (Alist)
C + + implementation
Code
Class Translation {public:string stringtranslation (string A, int n, int len) {//write code here String :: Iterator it; it = A.begin () + len; Reverse (A.begin (), it); Reverse (It,a.end ()); Reverse (A.begin (), A.end ()); return A; }};
2018-9-3 Night
This article is from "operations to Development" blog, please be sure to keep this source http://237085.blog.51cto.com/227085/1962364
Python programming Exercises-string shift exercises