Facebook
From LiLo, 3 Months ago, written in Plain Text.
This paste is a reply to Untitled from LiLo - view diff
Embed
Download Paste or View Raw
Hits: 45
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <set>
  5. #include <map>
  6. #include <list>
  7. #include <iterator>
  8.  
  9. #include <chrono>
  10.  
  11. using namespace std;
  12. using namespace std::chrono;
  13.  
  14. int main(void) {
  15.     auto start = high_resolution_clock::now();
  16.     int i = 0;
  17.     int f;
  18.     ifstream newfile;
  19.     newfile.open("testInput.txt");
  20.     auto stop = high_resolution_clock::now();
  21.     auto duration = duration_cast<microseconds>(stop - start);
  22.     cout << duration.count() << endl;
  23.  
  24.     if (newfile.is_open()) {
  25.         list<string*> l1;
  26.         map<string, map<string, int> > myOrder;
  27.        
  28.         string *p;
  29.         string line;
  30.         start = high_resolution_clock::now();
  31.         while (getline(newfile, line)) {
  32.             f = line.find("|");
  33.             p = new string[2];
  34.             /*cout << line << endl;*/
  35.             p[0] = (line.substr(0, f));
  36.             p[1] = (line.substr(f + 1, string::npos));
  37.  
  38.             if (myOrder.find(p[0]) == myOrder.end()) {
  39.                 //not found
  40.                 myOrder[p[0]][p[1]] = 1;
  41.             }
  42.             else {
  43.  
  44.                 if (myOrder[p[0]].find(p[1]) == myOrder[p[0]].end())
  45.                     myOrder[p[0]][p[1]] = myOrder[p[0]].size() + 1;
  46.             }
  47.             l1.push_back(p);
  48.            
  49.         }
  50.         stop = high_resolution_clock::now();
  51.         duration = duration_cast<microseconds>(stop - start);
  52.         cout << duration.count() << endl;
  53.  
  54.         newfile.close();
  55.         while (!l1.empty()) {
  56.             p = l1.front();
  57.            /* std::cout <<p[0]<<"|"<<p[1]<<"["<< myOrder[p[0]][p[1]] << " of " << myOrder[p[0]].size() <<"]"<< std::endl;*/
  58.             ofstream myfile;
  59.             myfile.open("example.txt", ios::app);
  60.             myfile << p[0] << "|" << p[1] << "[" << myOrder[p[0]][p[1]] << " of " << myOrder[p[0]].size() << "]" << std::endl;
  61.             myfile.close();
  62.             l1.pop_front();
  63.             delete[] p;
  64.         }
  65.     }  
  66. }