Cod sursa(job #3329849)

Utilizator andycristuAndrei Cristu andycristu Data 16 decembrie 2025 10:58:07
Problema Potrivirea sirurilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <fstream>
#include <cstring>
#include <string>
using namespace std;
ifstream cin ("strmatch.in");
ofstream cout ("strmatch.out");
string p;
string t;
string f;
void frontiera(string f[], string p[], int m)
{
    int q = 0, int k;
    for (q = 2;q <= m;q++)
    {
        if (p[k + 1] == p[q])
        {
            k = k + 1;
        }
        f[q] = k;
    }
}
int main()
{
    int n, i, j, m, q = 0, nr_g = 0;
    cin >> p;
    cin >> t;
    cout << p << " " << t;
    n = strlen(p);
    m = strlen(t);
    for (i = 1;i <= n,i++)
    {
        while (q > 0 && p[q + 1] != t[i])
        {
            q = f[q];
        }
        if (p[q + 1] == t[i])
        {
            q = q + 1;
        }
        else if (q == m)
        {
            nr_g++;
        }
    }
    return 0;
}