Wait for the courier to get bored-rotate the string

Source: Internet
Author: User

And so on-rotating strings

It was a speechless weekend. I waited for a few hours yesterday afternoon to deliver and bought two books 《CodeDaquan "and" programming Pearl ", there are other people's clothes. This morning, I ran to the company to wait for the express delivery, and other people's clothes. I haven't arrived yet. It's really speechless to do professional purchasing, I wanted to buy a ticket. I was speechless even though I had no chance to log on to the portal. I had to play.ProgramI saw the programming Pearl River yesterday. There is a problem in it about the rotation of strings. The question is as follows:

Returns the left-hand I position of an n-element vector. For example, if n = 8 and I = 3, the vector abcdefgh is rotated to defghabc. Can you use only dozens of extra bytes of storage space to complete vector rotation in a proportional time of n?

No more nonsense. Other junk methods are directly passed. It is best to directly look at the most correct methods. There is no time to write these methods, and there is no more time to explain them, I am about to launch express delivery. The Code is as follows:

# Include "  Stdafx. h  " 
# Include <iostream>
Using Namespace STD;

Void Change ( Char * Arr, Int Start, Int End)
{
End --;
While (Start <End)
{
Arr [start] ^ = arr [end];
Arr [end] ^ = arr [start];
Arr [start ++] ^ = arr [end --];
}
}

Void Wordwheel ( Char * Arr, Int Count, Int Length)
{
Change (ARR, 0 , Count );
Change (ARR, Count, length );
Change (ARR, 0 , Length );
}


// Test code
Int Main (){
Char STR [] = " Abcdefghijk " ;
Wordwheel (STR, 4 , 11 );
Cout <STR <Endl;
Getchar ();
Return 0 ;
}

 

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.