Cod sursa(job #1469970)

Utilizator Breje_RaulRaul Breje Breje_Raul Data 10 august 2015 00:00:34
Problema Potrivirea sirurilor Scor 18
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 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;
    for (int i=0; i<lengthSecondChar-lengthFirstChar; ++i){
        if (firstChar.compare(secondChar.substr(i,lengthFirstChar)) == 0){
            noOfTotal++;
            poss.push_back(i);
            i += lengthFirstChar;
        }
        if (noOfTotal >= 1000){
            break;
        }
    }
    out << noOfTotal << "\n";
    for (int i=0; i<poss.size(); ++i){
        out << poss.at(i) << " ";
    }
    return 0;
}