Cod sursa(job #1054008)

Utilizator costinbanuCostin Banu costinbanu Data 13 decembrie 2013 10:32:02
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef vector<int> vec;
typedef map<string, vec> ht;


int main(){
    ifstream f("abc2.in");
    ofstream g("abc2.out");
    string text, word;
    ht h;
    int nr = 0;
    f >> text >> word;
    do {
        int found = text.find(word);
        vec v;
        while (found != string::npos){
            v.push_back(found);
            found = text.find(word, found + word.size());
        }
        h[word].insert(h[word].end(), v.begin(), v.end());
        f >> word;
    } while (!f.eof());
    for (ht::iterator i = h.begin(); i != h.end(); i++)
        if (i->second.size() > 0)
            nr++;
    g << nr;
    f.close();
    g.close();
    return 0;
}