Cod sursa(job #2430955)

Utilizator ViAlexVisan Alexandru ViAlex Data 17 iunie 2019 13:51:19
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
ifstream in("strmatch.in");
ofstream out("strmatch.out");
string a,b;
void read()
{
    in>>a>>b;
}
void search_for(string what,string in)
{
    int size1=what.length();
    int size2=in.length();
    int cursor=0;
    int cursor_in_first=0;
    vector<int>solutions;
    while(cursor<size2)
    {
        if(in[cursor]==what[cursor_in_first])
        {
            cursor_in_first++;
            if(cursor_in_first==size1)
            {
                cursor=cursor-size1+1;
                solutions.push_back(cursor);
                cursor_in_first=0;
            }
        }
        else
        {
            cursor_in_first=0;
            if(in[cursor]==what[cursor_in_first])
                cursor_in_first++;
        }
        cursor++;
    }
    out<<solutions.size()<<endl;
    for(unsigned i=0; i<solutions.size(); i++)
    {
        out<<solutions[i]<<" ";
    }

}
int main()
{
    read();
    search_for(a,b);
}