Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <map>
- using namespace std;
- void Print(const vector<int>& v) {
- for (int i = 0; i < v.size(); ++i)
- cout << v[i] << " ";
- cout << endl;
- }
- int main() {
- ifstream myFile;
- myFile.open("file.txt");
- map<string, vector<int>> m;
- string s;
- int line = 0;
- while (!myFile.eof()) {
- myFile >> s;
- if (s.find('.') != string::npos)
- m[s].push_back(line++);
- else
- m[s].push_back(line);
- }
- map<string, vector<int>>::iterator it;
- for (it = m.begin(); it != m.end(); ++it) {
- cout << (*it).first << " = ";
- Print((*it).second);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement