Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include<iostream>
  2. #include<stack>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int N;
  7.     do {
  8. escape:
  9.         cin>>ws>>N;
  10.         do {
  11.             int tam=1, ordem, i;
  12.             stack<int> estacao;
  13.             for(i=0; i<N; i++) {
  14.                 cin>>ws>>ordem;
  15.                 if(ordem==0) {
  16.                     cout << endl;
  17.                     goto escape;
  18.                 }
  19.                 while(i<N) {
  20.                     if(estacao.size()>0) {
  21.                         if(estacao.top()==ordem) {
  22.                             estacao.pop();
  23.                             break;
  24.                         } else
  25.                             if(estacao.top()!=ordem && tam>=N) {
  26.                                 break;
  27.                             }
  28.                     }
  29.                     if(ordem!=tam && tam<N) {
  30.                         estacao.push(tam);
  31.                         tam++;
  32.                     }
  33.                     if(ordem==tam) {
  34.                         tam++;
  35.                         break;
  36.                     }
  37.  
  38.                 }
  39.  
  40.             }
  41.             if(ordem!=0) {
  42.                 escape2:
  43.                 if(estacao.size()==0) {
  44.                     cout << "Yes" << endl;
  45.                 } else
  46.                     cout << "No" << endl;
  47.             }
  48.         } while(N);
  49.     } while(N);
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement