fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX 100
  5.  
  6. int main(){
  7. system("cls");
  8.  
  9. char Str1[MAX]= "Hom nay thoi tiet mat mat";
  10. char Str2[MAX]= "mat";
  11.  
  12. // printf("nhap vao str1: ");
  13. // gets(Str1);
  14. // printf("Nhap vao str2: ");
  15. // gets(Str2);
  16.  
  17. int n = 0, m = 0, kp = 0;
  18. int doDaiStr2 = strlen(Str2);
  19.  
  20. while (Str1[n] != '\0')
  21. {
  22. if (Str1[n] == Str2[m])
  23. {
  24. while (Str1[n] == Str2[m] && Str1[n] != '\0')
  25. {
  26. n++;
  27. m++;
  28. }
  29. if (m == doDaiStr2 && (Str1[n] == ' ' || Str1[n] == '\0'))
  30. {
  31. kp++;
  32. }
  33. }else{
  34. while (Str1[n] != ' ')
  35. {
  36. n++;
  37. if(Str1[n] == '\0')
  38. break;
  39. }
  40. }
  41. n++;
  42. m = 0;
  43. }
  44. if (kp > 0)
  45. {
  46. printf("Chuoi \"%s\" tim duoc trong chuoi \"%s\" va so lan xuat hien la: %d", Str2, Str1, kp);
  47. }else{
  48. printf("Chuoi \"%c\" tim duoc trong chuoi \"%c\"", Str2, Str1);
  49.  
  50. }
  51.  
  52. return 0;
  53. }
  54.  
  55.  
Success #stdin #stdout #stderr 0.01s 5304KB
stdin
Standard input is empty
stdout
Chuoi "mat" tim duoc trong chuoi "Hom nay thoi tiet mat mat" va  so lan xuat hien la: 2
stderr
sh: 1: cls: not found