Advertisement
vardgrig

bilet2/4

Nov 30th, 2021
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6. void Print(const vector<int>& v) {
  7.     for (int i = 0; i < v.size(); ++i)
  8.         cout << v[i] << " ";
  9.     cout << endl;
  10. }
  11. int main() {
  12.     ifstream myFile;
  13.     myFile.open("file.txt");
  14.     map<string, vector<int>> m;
  15.     string s;
  16.     int line = 0;
  17.     while (!myFile.eof()) {
  18.         myFile >> s;
  19.         if (s.find('.') != string::npos)
  20.             m[s].push_back(line++);
  21.         else
  22.             m[s].push_back(line);
  23.     }
  24.     map<string, vector<int>>::iterator it;
  25.     for (it = m.begin(); it != m.end(); ++it) {
  26.         cout << (*it).first << " = ";
  27.         Print((*it).second);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement