#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100

int main(){
    system("cls");

    char Str1[MAX]= "Hom nay thoi tiet mat mat";
    char Str2[MAX]= "mat";

    // printf("nhap vao str1: ");
    // gets(Str1);
    // printf("Nhap vao str2: ");
    // gets(Str2);

    int n = 0, m = 0, kp = 0;
    int doDaiStr2 = strlen(Str2);

while (Str1[n] != '\0')
    {
        if (Str1[n] == Str2[m])
        {
            while (Str1[n] == Str2[m] && Str1[n] != '\0')
            {
                n++;
                m++;
            }
            if (m == doDaiStr2 && (Str1[n] == ' ' || Str1[n] == '\0'))
            {
                kp++;
            }
        }else{
            while (Str1[n] != ' ')
            {
                n++;
                if(Str1[n] == '\0')
                break;
            }   
        }
        n++;
        m = 0;      
    }
    if (kp > 0)
    {
        printf("Chuoi \"%s\" tim duoc trong chuoi \"%s\" va  so lan xuat hien la: %d", Str2, Str1, kp);
    }else{
        printf("Chuoi \"%c\" tim duoc trong chuoi \"%c\"", Str2, Str1);

    }
    
    return 0;
}

