Cod sursa(job #1488702)

Utilizator GalactusAnd Me Galactus Data 19 septembrie 2015 16:18:40
Problema Potrivirea sirurilor Scor 22
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
ofstream d("strmatch.txt");
int nr,m,a;
string s1,s2;

int main()
{
getline(f,s1);
getline(f,s2);
m=s2.length();
nr=0;
int k=0;
while(s2.find(s1)!=string::npos)
{
   if (nr<1000){
                d<<s2.find(s1)+k<<" ";
                k=s2.find(s1)+1;
                 s2.assign(s2.substr(s2.find(s1)+1,(m-s2.find(s1)-1)));
                nr++;}
                else {nr++;s2.assign(s1.substr(s2.find(s1),(m-s2.find(s1)-1)));}
}
f.close();
g<<nr<<endl;
d.close();
ifstream d("strmatch.txt");
for(int i=1;i<=nr;i++){d>>a;g<<a<<" ";}
g.close();
d.close();
}