Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <iostream.h>
- #include <string.h>
- void KiemTra(char s1[200],char s2[200])
- {
- int n = strlen(s1);
- int m = strlen(s2);
- int flag,count=0;
- for (int i=0;i<n-m+1;i++)
- if(s1[i] == s2[0])
- {
- flag=1;
- for(int j=i;j<i+m;j++)
- if (s1[j] != s2[j-i])
- flag=0;
- if (flag)
- count++;
- }
- if (count>0)
- cout<<"\n Xau '"<<s2<<"' xuat hien "<<count<< " lan trong xau '"<<s1<<"'";
- else
- cout<<"\n Xau '"<<s2<<"' khong xuat hien trong xau '"<<s1<<"'";
- }
- main ()
- {
- char s1[200],s2[200];
- cout<<"Nhap xau s1 : "; gets(s1);
- cout<<"Nhap xau s2 : "; gets(s2);
- int n = strlen(s1);
- int m = strlen(s2);
- if (n>m)
- KiemTra(s1,s2);
- else
- KiemTra(s2,s1);
- getch();
- }
Add Comment
Please, Sign In to add comment