Delete a substring. All substrings are deleted as long as the original substring has the same substring. The substring must contain at least two characters.

Source: Internet
Author: User
// Delete the substrings. If the original substrings have the same substrings, all substrings are deleted. The substring must contain at least two characters. # Include <stdio. h> # include <string. h> char * delete_string (char s [], char a []); int main () {char s [255]; char data [255] [255]; // store the same substring int I, j, k; int length; int ROW = 0, column; // gets (s); length = strlen (s); // find the same substring for (I = 0; I <length-3; I ++) {for (j = I + 1; j <length-1 ;) {If (S [I] = s [J]) & (s [I + 1] = s [J + 1]) {Column = 0; k = 0; do {data [row] [column ++] = s [J]; j ++; k ++ ;} while (s [I + k] = s [J]); Data [row ++] [column] = '\ 0';} else {J ++ ;}} puts ("the same string :"); for (I = 0; I <row; I ++) {puts (data [I]); // output the same substring} for (I = 0; I <row; I ++) {delete_string (S, data [I]) ;}puts ("after deleted:"); puts (s); Return 0 ;} // function: If String S contains sub-string a, delete a from string S. Otherwise, no changes will be made. Char * delete_string (char s [], char a []) {int length_s; int length_a; int I, j, k; length_s = strlen (s ); length_a = strlen (a); for (I = 0; I <length_s;) {J = 0; If (s [I] = A [J]) {do {I ++; j ++;} while (j <length_a) & (s [I] = A [J]); if (j = length_a) {// indicates that S contains the substring A and deletes it. For (k = I; k <= length_s; k ++) {s [k-length_a] = s [k];} I = I-length_a; j = 0 ;} else {J = 0 ;}} else {I ++ ;}} return s ;}

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: info-contact@alibabacloud.com 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.