Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <queue>
- #include <string>
- #include <cstdio>
- using namespace std; //Comando para evitar ter que declarar variaveis globais
- int main(){
- int endoffile;
- while(cin >> endoffile){
- bool pilha = true;
- bool lista = true;
- bool listap = true;
- //Cria fila, pilha e fila prioritaria de ints
- queue<int> l;
- stack<int> p;
- priority_queue<int> lp;
- int AdcRem = 0;
- int valor = 0;
- while(endoffile > 0){
- scanf("%d %d",&AdcRem,&valor);
- //Se os valores forem um,
- //adicione em cada tipo de estrutura o valor
- if (AdcRem == 1){
- if(pilha == true){
- p.push(valor);
- }
- if(lista == true){
- l.push(valor);
- }
- if(listap == true){
- lp.push(valor);
- }
- } else {
- //Se o valor nao for 1 remova de cada estrutura
- //Antes veja se esta vazia,
- //Depois veja se o ultimo/primeiro/maior valor e igual ao removido
- if (pilha == true){
- if(!p.empty() && p.top() == valor){
- p.pop();
- } else {
- pilha = false;
- }
- }
- if (lista == true){
- if(!l.empty() && l.front() == valor){
- l.pop();
- } else {
- lista = false;
- }
- }
- if (listap == true){
- if(!lp.empty() && lp.top() == valor){
- lp.pop();
- } else {
- listap = false;
- }
- }
- }
- endoffile--;
- }
- int contador;
- contador = 0;
- if (pilha == true){contador++;}
- if (lista == true){contador++;}
- if (listap == true){contador++;}
- if (contador == 0){cout << "impossible" << endl;}
- else if (contador > 1){cout << "not sure" << endl;}
- else if (contador == 1){
- if (pilha == true){cout << "stack" << endl;}
- else if (lista == true){cout << "queue" << endl;}
- else {cout << "priority queue" << endl;}
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement