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 ;
}