#include <stdlib.h> #include <stdio.h> #include <string.h> int str_split(char *input, char *output, int *out) { char *p; int i,in_len,len,max,flag; in_len = strlen(input); for(len =1,max=1; len <= in_len; len++) { if( 0 != (in_len%len) ) continue; for(i=0, flag =1, p = input; i< in_len/len; i++) { if(0 != memcmp(p, input, len) ) { flag = 0; break; } p += len; } if( (1 == flag) && ( (in_len/len) > max) ) { max = in_len/len; } } *out = max; memcpy(output, input, in_len/max); return 0; } int main(void ) { char input[100] = {0}; char output[100] = {0}; int n = 0; scanf("%s", input); str_split(&input[0], &output[0], &n); printf("str:%s, n:%d\n", output, n); return 0; }
时间: 2024-10-12 04:41:11