Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <cmath>
  5. #include <stack>
  6. #include <vector>
  7. #include <fstream>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     string name,nm,n;
  13.     string znach;
  14.     char s;
  15.     vector<string> q;
  16.     vector<string> lastname;
  17.     bool ln = NULL;
  18.     vector<string> res;
  19.     fstream fout;
  20.     cout << "Vvedite nazvanie faila" << endl;
  21.     cin >> name;
  22.     fout.open(name, ios::in);
  23.  
  24.     if (fout.is_open())
  25.     {
  26.         while (fout){
  27.             fout >> s;
  28.             if (s == '='|| s =='?'|| s == '&'){
  29.                 q.push_back(nm);
  30.                 nm.clear();
  31.                 nm.push_back(s);
  32.                 q.push_back(nm);
  33.                 nm.clear();
  34.             }
  35.             else nm.push_back(s);
  36.         }
  37.     }
  38.    
  39.     fout.close();
  40.     ofstream out;
  41.     out.open("/Users/redsquirrel/Desktop/output.txt",ios::app);
  42.    
  43.    
  44.     for (int i = 0 ; i < q.size() ; ++i){
  45.        
  46.         if (q[i] == "=")
  47.             n = q[i-1];
  48.        
  49.         for (auto g : lastname)
  50.             if (n == g){
  51.                 ln = 1;
  52.                 break;
  53.                 }
  54.        
  55.        
  56.  
  57.        
  58.        
  59.        
  60.         if (!ln){
  61.             for (int j = 0 ; j < q.size()-2 ; ++j){
  62.            
  63.             if (q[j] == n)
  64.                 res.push_back(q[j+2]);
  65.             }
  66.                 if (!res.empty()){
  67.                    
  68.                     out << n << "=[";
  69.                     for(int k = 0 ; k < res.size() ; ++k){
  70.                        
  71.                         if (k==0 && k==res.size()-1){
  72.                             out << res[k] << ']';
  73.                             break;
  74.                         }
  75.                        
  76.                         if (k==0)
  77.                         out << res[k] <<", ";
  78.                         else{
  79.                        
  80.                         if (k == res.size()-1)
  81.                             out << res[k] << ']' << ' ';
  82.                            
  83.                         else out << res[k];
  84.                             }
  85.                     }
  86.                     }
  87.            
  88.                     res.clear();
  89.                    
  90.                
  91.         }
  92.         ln = 0;
  93.         lastname.push_back(n);
  94.        
  95.     }
  96.     out.close();
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement