Cod sursa(job #1469975)

Utilizator Breje_RaulRaul Breje Breje_Raul Data 10 august 2015 00:21:07
Problema Potrivirea sirurilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <vector>

using namespace std;

string firstChar, secondChar;

int main() {
    ifstream in("strmatch.in");
    ofstream out("strmatch.out");
    in >> firstChar >> secondChar;
    int lengthFirstChar = firstChar.size();
    int lengthSecondChar = secondChar.size();
    int noOfTotal = 0;
    vector<int> poss;
    bool isEnded = false;
    int pos = 0, step = 0;
    while (secondChar.size() > 0){
        pos = secondChar.find(firstChar);
        if (pos != string::npos){
            noOfTotal++;    
            poss.push_back(step + pos);
            step += pos+lengthFirstChar-1;
            secondChar = secondChar.substr(pos, secondChar.size()-lengthFirstChar);
        }
    }
    out << noOfTotal-1 << "\n";
    for (int i=0; i<poss.size()-1; ++i){
        out << poss.at(i) << " ";
    }
    return 0;
}