Cod sursa(job #1228734)

Utilizator cdascaluDascalu Cristian cdascalu Data 15 septembrie 2014 11:54:53
Problema Potrivirea sirurilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include<fstream>
#include<iostream>
#include<string>
#include<list>
#define MOD1 99991
#define MOD2 99871
#define B1 10
#define B2 23
using namespace std;


void read(string &A, string &B)
{
    ifstream f("strmatch.in");
    f>>A>>B;
    f.close();
}
void write(const int &nr_sol, const list<int> &sol)
{
    ofstream g("strmatch.out");
    g<<nr_sol<<"\n";
    for(auto it = sol.begin(); it != sol.end(); ++it)
        g<<*it<<" ";
    g.close();
}
int main()
{
    string A, B;
    read(A, B);

    int found = B.find(A), nr_sol;
    list<int> sol;
    for(nr_sol = 0; found != string::npos; found = B.find(A, found + 1), ++nr_sol)
    {
        if(nr_sol < 1000)
            sol.push_back(found);
    }
    write(nr_sol, sol);
    return 0;
}