Cod sursa(job #1469967)

Utilizator Breje_RaulRaul Breje Breje_Raul Data 9 august 2015 23:52:43
Problema Potrivirea sirurilor Scor 38
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 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);
        }
    }
    out << noOfTotal << "\n";
    for (int i=0; i<poss.size(); ++i){
        out << poss.at(i) << " ";
    }
    return 0;
}