Python programming Exercises-string shift exercises

Source: Internet
Author: User


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.