Sunday, May 7, 2017

URI Online Judge Solution 1062 Rails - Solution in C, C++ | Data structures

URI Online Judge Solution 1062 Rails - Solution in C, C++ | Data structures


URI Online Judge Solution 1062 Rails | Data structures
URI Main Problem Link -

Problem Name: URI Problem 1062 Rails
Problem Number : URI Problem 1062 Rails Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus



URI Online Judge Solution 1062 Rails - Solution in C, C++ | Data structures

URI Solution 1062 Rails Code in CPP:


URI Online Judge Solution 1062 Rails Code:


#include <cstdio>
#include <stack>

using namespace std;

#define sc1(a) scanf("%d", &a)
#define fr(i, a, n) for(int i = (a); i < (n); i++)
#define fe(i, a, n) for(int i = (a); i <= (n); i++)

typedef stack<int> si;
 
int vet[1005];

int main(int argc, char const *argv[])
{
 int i, curr, n, top;

 while(sc1(n) && n)
 {
  while(sc1(vet[0]) && vet[0])
  {
   fr(i, 1, n)
    sc1(vet[i]);

   si p;
   curr = 0;

   fe(i, 1, n)
   {
    p.push(i);

    while(p.size() > 0 && vet[curr] == p.top())
    {
     curr++;
     p.pop();
    }
   }

   (p.size() == 0) ? puts("Yes") : puts("No");
  }

  printf("\n");
 }

 return 0;
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.