Cod sursa(job #3162630)

Utilizator AnSeDraAndrei Sebastian Dragulescu AnSeDra Data 29 octombrie 2023 15:57:11
Problema Potrivirea sirurilor Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream>
#include <string>
#include <vector>

using namespace std;

const int Imax = 1000;

string a, b, aux;
vector<int> poz;

int main(){
    ifstream fin("strmatch.in");
    ofstream fout("strmatch.out");

    int k, cnt;

    fin >> a >> b;


    if(a.size() == b.size()){
        if(a == b){
            fout << 1 << '\n' << 1;
        }
        else{
            fout << 0;
        }
    }
    else{
        k = a.size();
        for(int i = 0; i < k - 1; i++){
            aux.push_back(b[i]);
        }

        cnt = 0;
        for(unsigned int i = k - 1; i < b.size(); i++){
            aux.push_back(b[i]);

            if(aux == a){
                cnt++;
                if(poz.size() < Imax){
                    poz.push_back(i - k + 1);
                }
            }

            aux.erase(aux.begin());
        }


        fout << cnt << '\n';
        for(unsigned int i = 0; i < poz.size(); i++){
            fout << poz[i] << " ";
        }
    }


    return 0;
}