I Can Guess the Data Structure! UVA11995

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string>    
#include <sstream>
#include <utility>   
#include <ctime>

using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;
using std::endl;

char print[3][20] = {"stack", "queue", "priority queue"};

int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		stack<int> st;
		queue<int> que;
		priority_queue<int> pque;
		bool is[3] = {true, true, true};
		int op, num;
		for(int i = 0; i < n; ++i)
		{
			scanf("%d%d", &op, &num);
			if(is[0])
			{
				if(op == 1)
				{
					st.push(num);
				}
				else
				{
					if(st.empty() || st.top() != num)
						is[0] = false;
					else
						st.pop();
				}
			}
			if(is[1])
			{
				if(op == 1)
				{
					que.push(num);
				}
				else
				{
					if(que.empty() || que.front() != num)
						is[1] = false;
					else
						que.pop();
				}
			}
			if(is[2])
			{
				if(op == 1)
				{
					pque.push(num);
				}
				else
				{
					if(pque.empty() || pque.top() != num)
						is[2] = false;
					else
						pque.pop();
				}
			}
		}
		int ans, count = 0;
		for(int i = 0; i < 3; ++i)
			if(is[i])
			{
				++count;
				ans = i;
			}
		switch(count)
		{
			case 0:		printf("impossible\n"); break;
			case 1:		printf("%s\n", print[ans]); break;
			default:	printf("not sure\n"); break;
		}
	}
	return 0;
}

你可能感兴趣的:(I Can Guess the Data Structure! UVA11995)