The C language determines whether a string is another rotation of any bit derived

Source: Internet
Author: User

Tag: c; Rotate string

/************************************************************************************4. A string that determines whether a string is rotated after another string. For example: Given S1&NBSP;=&NBSP;AABCD and S2&NBSP;=&NBSP;BCDAA, return 1, given S1=ABCD and S2=ACBD, return 0. Aabcd left one character get abcdaaabcd two characters get BCDAAAABCD right spin one character get DAABCAABCD right spin two characters get cdaab*************************************** /#include  <stdio.h> #include <assert.h> #include <string.h>int is_rotate_num (const char *aim,char *source) {char *pstart =  source;char *pend = source;int i = 0,j=0;assert (Aim&&source);   (strlen (AIM)  != strlen (source))//String length unequal   certainly not return 0;while  (* (Pend)) {Char  ch = *pstart;while  (* (pstart + 1)) {*pstart = * (pstart + 1); pstart++;} *pstart = ch;pstart = source;if  (strcmp (aim, source)  == 0) return  1;pend++;} return 0;} Int main () {char arr[] =  "I am handsome!"; printf ("%d\n",  is_rotate_num ("! I'm Handsome",arr ));// 0  not   1  is printf ("%s\n", arr) ;//output rotated string   contrast return 0;}

The C language determines whether a string is another rotation of any bit derived

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: 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.