LeetCode—796. 旋轉字串
阿新 • • 發佈:2019-02-20
#include <stdio.h> #include <stdlib.h> int rotateString(char* A, char* B) { int i,len,k; char ch; len=strlen(A); for(k=1;k<=len;k++) { ch=A[0]; for(i=0;i<len-1;i++) { A[i]=A[i+1]; } A[len-1]=ch; if(strcmp(A,B)==0) break; } if(strcmp(A,B)==0) return 1; else return 0; } int main() { //A = 'abcde', B = 'cdeab' "abcde" char A[]="abcde"; char B[]="abced"; int t=rotateString(A,B); if(t==1) printf("343lo world!\n"); else printf("sdfghj\n"); return 0; }