UVa 11995 I Can Guess the Data Structure! (STL)
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3146
注意“without error”这句。
/*0.036s*/
#include<cstdio>
#include<queue>
#include<stack>
using namespace std;
const int maxn = 1000 + 10;
int n, t[maxn], v[maxn];
int check_stack()
{
stack<int> s;
for (int i = 0; i < n; i++)
{
if (t[i] == 2)
{
if (s.empty()) return 0;
int x = s.top();
s.pop();
if (x != v[i]) return 0;
}
else s.push(v[i]);
}
return 1;
}
int check_queue()
{
queue<int> s;
for (int i = 0; i < n; i++)
{
if (t[i] == 2)
{
if (s.empty()) return 0;
int x = s.front();
s.pop();
if (x != v[i]) return 0;
}
else s.push(v[i]);
}
return 1;
}
int check_pq()
{
priority_queue<int> s;
for (int i = 0; i < n; i++)
{
if (t[i] == 2)
{
if (s.empty()) return 0;
int x = s.top();
s.pop();
if (x != v[i]) return 0;
}
else s.push(v[i]);
}
return 1;
}
int main()
{
while (~scanf("%d", &n))
{
for (int i = 0; i < n; i++) scanf("%d%d", &t[i], &v[i]);
int s = check_stack();
int q = check_queue();
int pq = check_pq();
if (!s && !q && !pq) printf("impossible\n");
else 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 printf("not sure\n");
}
return 0;
}
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |