#include <vector>
#include <iostream>
#include <string>
#include <map>
using namespace std;
class document
{
public:
void missingMap(string, int);
void displayMap() const; // this should be const
private:
map<string, vector<int>> misspelled;
};
void document::missingMap(string word, int lineNum)
{
misspelled[word].push_back(lineNum);
}
void document::displayMap() const // this should be const
{
typedef map<string, vector<int>>::const_iterator map_iter;
typedef vector<int>::const_iterator vec_iter;
for ( map_iter i = misspelled.begin(); i!= misspelled.end(); ++i )
{
cout << i->first << ": ";
for (vec_iter j = i->second.begin(); j != i->second.end(); ++j)
{
cout << *j << ' ' /* << endl */; // Don't end the line here.
}
cout << '\n'; // end the line here.
}
}
int main()
{
document doc;
doc.missingMap("debugging", 1);
doc.missingMap("process", 2);
doc.missingMap("removing", 2);
doc.missingMap("programming", 3);
doc.missingMap("process", 4);
doc.missingMap("putting", 4);
doc.displayMap();
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8bWFwPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIGRvY3VtZW50CnsKcHVibGljOgogICAgdm9pZCBtaXNzaW5nTWFwKHN0cmluZywgaW50KTsKICAgIHZvaWQgZGlzcGxheU1hcCgpIGNvbnN0OyAgICAgICAgICAgIC8vIHRoaXMgc2hvdWxkIGJlIGNvbnN0Cgpwcml2YXRlOgogICAgbWFwPHN0cmluZywgdmVjdG9yPGludD4+IG1pc3NwZWxsZWQ7Cn07CgoKCnZvaWQgZG9jdW1lbnQ6Om1pc3NpbmdNYXAoc3RyaW5nIHdvcmQsIGludCBsaW5lTnVtKQp7CiAgICBtaXNzcGVsbGVkW3dvcmRdLnB1c2hfYmFjayhsaW5lTnVtKTsKfQoKdm9pZCBkb2N1bWVudDo6ZGlzcGxheU1hcCgpIGNvbnN0ICAgICAgIC8vIHRoaXMgc2hvdWxkIGJlIGNvbnN0CnsKICAgIHR5cGVkZWYgbWFwPHN0cmluZywgdmVj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