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