本文主要是介绍UVA - 11995 I Can Guess the Data Structure!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:求满足操作的数据结构
思路:模拟
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;int n,o,e,cs,s,q,pq;int main(){while (scanf("%d",&n) != EOF){stack<int > st;queue<int > qu;priority_queue<int > pqu;s = q = pq = 1;while (n--){scanf("%d %d",&o,&e);if (o == 1){st.push(e);qu.push(e);pqu.push(e);}else if (o == 2){if (!st.empty()){if (st.top() != e)s = 0;st.pop();}else s = 0;if (!qu.empty()){if (qu.front() != e)q = 0;qu.pop();}else q = 0;if (!pqu.empty()){if (pqu.top() != e)pq = 0;pqu.pop();}else pq = 0;}}if (s && !q && !pq)printf("stack\n");else if (!s && q && !pq)printf("queue\n");else if (!s && !q && pq)printf("priority queue\n");else if (!s && !q && !pq)printf("impossible\n");else printf("not sure\n");}return 0;
}
这篇关于UVA - 11995 I Can Guess the Data Structure!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!