Jz-c-42-plus

Source: Internet
Author: User

Sword Point 42nd-Expand: Left rotation string: Left rotation operation is to transfer several characters in front of the string to the end of the string, such as input "ABCDEFG" and the number 2, left rotation 2 bit after: "Cdefgab"

1 //============================================================================2 //Name:jz-c-42-plus.cpp3 //Author:laughing_lz4 //Version:5 //Copyright:all Right Reserved6 //Description: Left rotation string: The left rotation operation is to transfer several characters in front of the string to the end of the string, such as input "ABCDEFG" and the number 2, left rotation 2 bit after: "Cdefgab"7 //============================================================================8 9#include <iostream>Ten#include <stdio.h> One#include"StringUtil.h" A#include <string.h> - using namespacestd; -  the Char* Leftrotatestring (Char* PStr,intN) { -     if(PStr! =NULL) { -         intNlength = static_cast<int>(strlen (PSTR)); -         if(Nlength >0&& n >0&& N <nlength) { +             Char* Pfirststart =pStr; -             Char* Pfirstend = pStr + N-1; +             Char* Psecondstart = pStr +N; A             Char* Psecondend = pStr + nlength-1; at             //flips the front n characters of a string - Reverse (Pfirststart, pfirstend); -             //flips the back part of a string - Reverse (Psecondstart, psecondend); -             //Flip the entire string - Reverse (Pfirststart, psecondend); in         } -     } to  +     returnpStr; - } the  * //==================== test Code ==================== $ voidTest (Char* TestName,Char* Input,intNumChar*Expectedresult) {Panax Notoginseng     if(TestName! =NULL) -printf"%s begins:", testname); the  +     Char* result =leftrotatestring (input, num); A  the     if(Input = = NULL && Expectedresult = =NULL) +|| (Input! = NULL && strcmp (result, expectedresult) = =0)) -printf"passed.\n\n"); $     Else $printf"failed.\n\n"); - } -  the //Functional Testing - voidTest1 () {Wuyi     CharInput[] ="ABCDEFG"; the     CharExpected[] ="Cdefgab"; -  WuTest ("Test1", input,2, expected); - } About  $ //Boundary Value Test - voidTest2 () { -     CharInput[] ="ABCDEFG"; -     CharExpected[] ="BCDEFGA"; A  +Test ("Test2", input,1, expected); the } -  $ //Boundary Value Test the voidTest3 () { the     CharInput[] ="ABCDEFG"; the     CharExpected[] ="Gabcdef"; the  -Test ("Test3", input,6, expected); in } the  the //Robustness Testing About voidTest4 () { theTest ("Test4"Null6, NULL); the } the  + //Robustness Testing - voidTest5 () { the     CharInput[] ="ABCDEFG";Bayi     CharExpected[] ="ABCDEFG"; the  theTest ("Test5", input,0, expected); - } -  the //Robustness Testing the voidTest6 () { the     CharInput[] ="ABCDEFG"; the     CharExpected[] ="ABCDEFG"; -  theTest ("Test6", input,7, expected); the } the 94 intMainintargcChar**argv) { the Test1 (); the Test2 (); the Test3 ();98 Test4 (); About Test5 (); - Test6 ();101 102     return 0;103}

Jz-c-42-plus

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.