Home > Back-end >  How to split a string into an arbitrary string and output?
How to split a string into an arbitrary string and output?

Time:10-21

Such as topic, how to split a string into any jokes string and output??
For example: the abcd is divided into two segments with a BCD, ab CD, ABC d
For a very long string, need is divided into many segments to do? Ask leaders to solve!

CodePudding user response:

Backtracking algorithm enumeration violence,

CodePudding user response:

Binary cutting point
Such as the abcd
There are three cutting point in 3 bit binary representation
Cycle from 0 to 8
Each number is converted to binary
Such as 5 to 101
1 said cutting
0 means no cutting
101 cutting result is
A BC d
And so on

CodePudding user response:

C + + file operations, put the string into the file, for a long period of more also can

CodePudding user response:

Permutation and combination problem
 # define SIZE 20 
Void the split (char * s, char (* c) [SIZE], int pos, int num) {
Int len=(int) strlen (s);
If (num==1) {
for (int i=0; iPrintf (" % s ", (char *) (c + I));
}
Printf (" % s \ n ", s);
return;
} else if (strlen (s) & lt;=1) {
return;
}
For (int I=1; iMemset ((char *) (c + pos), '\ 0', the SIZE * sizeof (char));
Memcpy ((char *) (c + pos), s, I);
The split (s + I, c, pos + 1, num - 1);
}
}

Int main (int arg c, const char * argv []) {
Char s [SIZE]={" abcde "};
Int len=(int) strlen (s);
For (int I=2; iChar (* c) [SIZE]=(char (*) [SIZE]) malloc (sizeof (char [SIZE]) * I);
The split (s, c, 0, I);
Free (c);
}
return 0;
}
  • Related