Wednesday, May 10, 2017

URI Solution 1340 Can Guess the Data Structure! | Data Structures

URI Solution 1340 Can Guess the Data Structure! | Data Structures


URI Online Judge Solution  | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1340

Problem Name: URI Problem 1340 Can Guess the Data Structure!
Problem Number : URI Problem 1340 Can Guess the Data Structure!  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1340 Can Guess the Data Structure! | Data Structures


URI Solution 1340 Can Guess the Data Structure!  Code in CPP:


#include <cstdio>
#include <stack>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
 int n, x, y;
 bool _p, _q, _s;

 while(scanf("%d", &n) != EOF){
  priority_queue<int> p;
  queue<int> q;
  stack<int> s;
  _p = true, _q = true, _s = true; 

  for (int i = 0; i < n; ++i)
  {
   scanf("%d %d", &x, &y);
   if(x == 1){
    p.push(y);
    q.push(y); 
    s.push(y);
   }else{
    if(p.top() != y) _p = false;
    if(q.front() != y) _q = false;
    if(s.top() != y) _s = false;
    p.pop(); q.pop(); s.pop();
   }
  }

  if((_p && _q && _s) || (!_p && _q && _s) || (_p && !_q && _s) || (_p && _q && !_s)) printf("not sure\n");
  else if (_p && !_q && !_s) printf("priority queue\n");
  else if (!_p && _q && !_s) printf("queue\n");
  else if (!_p && !_q && _s) printf("stack\n");
  else printf("impossible\n");
 }

 return 0;
}

Tag: Uri solve 1340 Can Guess the Data Structure! , Uri solution 1340 Can Guess the Data Structure! , URI oj Solve 1340 Can Guess the Data Structure!

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.