Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0e7a024

Browse files
committed
Add Solution for guessthedatastructure [OpenKattis]
1 parent 86bed4b commit 0e7a024

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="problem.png" />
206 KB
Loading[フレーム]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int x, a, b;
8+
9+
10+
11+
while (cin >> x)
12+
{
13+
queue <int> q;
14+
stack <int> s;
15+
priority_queue <int> p;
16+
17+
int n (1), m (1), l (1);
18+
for (int test = 0; test < x; test++)
19+
{
20+
cin>>a>>b;
21+
22+
if (a == 1)
23+
{
24+
q.push(b), s.push(b), p.push(b);
25+
}
26+
else
27+
{
28+
if (q.empty() || s.empty() || p.empty())
29+
{
30+
n = 0;
31+
m =0;
32+
l =0;
33+
}
34+
else
35+
{
36+
if (b != q.front()) n = 0;
37+
if (b != p.top()) l = 0;
38+
if (b != s.top()) m = 0;
39+
q.pop(), s.pop(), p.pop();
40+
}
41+
}
42+
}
43+
44+
if (n + m +l == 0)cout << "impossible\n";
45+
else if (n + m + l > 1)cout<<"not sure\n";
46+
else if (n)cout << "queue\n";
47+
else if (m)cout<<"stack\n";
48+
else cout << "priority queue\n";
49+
}
50+
51+
52+
return 0;
53+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /