Advertisement
myname0

практика_стек2_7

Jun 30th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <stack>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12.         ifstream in ("input.txt");
  13.         ofstream out ("output.txt");
  14.  
  15.         int n, k;
  16.         in >> n >> k;  
  17.         vector <stack<int>> vec (n);
  18.         int tmp;
  19.         int tmpe;
  20.         string temp;
  21.         string a;
  22.        
  23.         for(int i = 0; i < k; i++)
  24.         {
  25.                 in >> a;
  26.                 if(a[1] == 'U')
  27.                 {
  28.                     temp = a.substr(a.find('(') + 1, a.find('(') - a.find(',') - 1);
  29.                     tmp = atoi(temp.c_str()) - 1;
  30.                     temp = a.substr(a.find(',') + 1, a.find(',') - a.find(')') - 1);
  31.                     tmpe = atoi(temp.c_str());
  32.                     vec[tmp].push(tmpe);
  33.                 }
  34.                 else if (a[0] == 'T')
  35.                 {
  36.                     temp = a.substr(a.find('(') + 1, a.find('(') - a.find(',') - 1);
  37.                     tmp = atoi(temp.c_str()) - 1;                  
  38.                     out << vec[tmp].top() << " ";
  39.                 }
  40.                 else if (a[0] == 'P')
  41.                 {
  42.                     temp = a.substr(a.find('(') + 1, a.find('(') - a.find(',') - 1);
  43.                     tmp = atoi(temp.c_str()) - 1;
  44.                     out << vec[tmp].top() << " ";
  45.                     vec[tmp].pop();
  46.                 }
  47.            
  48.         }  
  49.        
  50.         in.close();
  51.         out.close();
  52.        
  53.         return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement