Cod sursa(job #2909314)

Utilizator test9265test9265 test9265 Data 12 iunie 2022 17:32:01
Problema Potrivirea sirurilor Scor 36
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ifstream fin;    fin.open("strmatch.in");
    ofstream fout; fout.open("strmatch.out");
    
    string A, B;
    map<char, int> mp;
    vector<int> v;
    fin >> A >> B;
    
    int count=0, i, j, la=A.length(), lb=B.length();
    for (i=0; i<la-1; i++) mp[A[i]]=la-i-1;
    
    for (i=0; i<lb-la;)
    {
        j=la-1;
        while (A[j]==B[i+j] && j>=0) j--;
        if (j<0)
        {
            v.push_back(i);
            count++;
            i++;
        }
        else i+=max(mp[B[i+j]],1);
    }
    fout << count <<'\n';
    for (auto c:v) fout << c <<' ';
    
    fin.close();
    fout.close();
}