Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. #include <stdio.h>
  2. //#include <conio.h>
  3. #include <string>
  4. #include <vector>
  5. #include <math.h>
  6. #include <stack>
  7. #include <queue>
  8. #include <algorithm>
  9. #include <stdlib.h>
  10. #include <iostream>
  11. using namespace std;
  12. int dem = 0, k, p,c,x;
  13.  
  14. int **ppt;
  15. char ch;
  16.  
  17.  
  18. int main()
  19. {
  20.     scanf("%d%d", &p, &c);
  21.     while (p)
  22.     {
  23.         dem++;
  24.         vector<int> kq;
  25.         queue<int**> que;
  26.  
  27.         stack<int**> pri;
  28.         vector<int**> v;
  29.         if (p < c)
  30.             k = p;
  31.         else
  32.             k = c;
  33.         v.resize(k + 1);
  34.         for (int i = 1; i <= k; i++)
  35.         {
  36.             ppt = new int*;
  37.             *ppt = new int;
  38.             **ppt = i;
  39.             v[i] = ppt;
  40.             que.push(ppt);
  41.         }
  42.         for (int i = 0; i < c; i++)
  43.         {
  44.             ch = getchar();
  45.             ch = getchar();
  46.             if (ch == 'N')
  47.             {
  48.                 while (pri.empty() == false && **pri.top() == -1)
  49.                     pri.pop();
  50.                    
  51.                
  52.                 if (pri.empty() == false)
  53.                 {
  54.                     kq.resize(kq.size() + 1);
  55.                     kq[kq.size() - 1] = **pri.top();
  56.                     if (k < c)
  57.                     {
  58.                         que.push(pri.top());
  59.                     }
  60.                     pri.pop();
  61.                 }
  62.                 else
  63.                 {
  64.                     while (**(que.front()) == -1)
  65.                         que.pop();
  66.                     kq.resize(kq.size() + 1);
  67.                     kq[kq.size() - 1] = **que.front();
  68.                     if (k < c)
  69.                     {
  70.                         que.push(que.front());
  71.                     }
  72.                     que.pop();
  73.                 }
  74.  
  75.                
  76.  
  77.  
  78.  
  79.             }
  80.             else
  81.             {
  82.                 scanf("%d", &x);
  83.                
  84.  
  85.  
  86.                 ppt = new int*;
  87.                 *ppt = new int;
  88.                 **ppt = x;
  89.  
  90.                 if (x <= k)
  91.                 {
  92.                     **v[x] = -1;
  93.                     v[x] = ppt;
  94.                 }
  95.  
  96.                
  97.                 pri.push(ppt);
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.             }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.         }
  119.         printf("Case %d:\n", dem);
  120.         for (int i = 0; i < kq.size(); i++)
  121.             printf("%d\n", kq[i]);
  122.         scanf("%d%d", &p, &c);
  123.     }
  124.  
  125.     //_getch();
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement