Pagini recente » Cod sursa (job #1787208) | Cod sursa (job #913170) | Cod sursa (job #530737) | Cod sursa (job #510529) | Cod sursa (job #1469975)
#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;
}