1 #include <iostream>
2 #include <stdio.h>
3 using namespace std;
4 int main(int argc, char *argv[])
5 {
6 char str1[50],str2[50],str3[50],*p1,*p2,*p3;
7 int num=0;
8 cout<<"输入两个子串\n";
9 gets(str1);
10 gets(str2);
11 p1=str1;
12 p2=str2;
13 p3=str3;
14 while(*p1!='\0')
15 {
16 if(*p1==*p2)
17 {
18 while(*p1==*p2&&*p2!='\0')
19 {
20 p1++;
21 p2++;
22 }
23 }
24 else {
25 // cout<<*p1<<endl;
26 *p3=*p1;
27 p1++;
28 p3++;
29 }
30
31 if(*p2=='\0')
32 num++;
33 p2=str2; //p2重新指向str2,然后通过循环接着找
34 }
35 *p3='\0'; //关键部分,不然输出的字符数组是不完整的
36 cout<<"子串个数:"<<num<<endl;
37 cout<<"删除重复子串后:"<<str3<<endl;
38
39 return 0;
40 }