-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2022-05-31.cpp
More file actions
93 lines (85 loc) · 1.02 KB
/
2022-05-31.cpp
File metadata and controls
93 lines (85 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
namespace Mongshell
{
int main()
{
queue<int> q;
int n, k;
int cnt = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
q.push(i);
}
while (q.size() != 1)
{
cnt++;
if (cnt == k)
{
cnt = 0;
}
else
{
q.push(q.front());
}
q.pop();
}
cout << q.front() << endl;
return 0;
}
}
int main()
{
stack<int> st;
queue<char> q;
int n;
int* train;
int cnt(1);
bool isPossible = true;
cin >> n;
train = new int[n];
for (int i = 0; i < n; i++)
{
cin >> train[i];
}
st.push(train[0]);
q.push('P');
for (int i = 0;cnt <= n;i)
{
if (st.empty()&& i < n)
{
st.push(train[i++]);
}
if (st.top() == cnt)
{
++cnt;
st.pop();
q.push('O');
}
else
{
if (i >= n)
{
isPossible = false;
break;
}
st.push(train[i++]);
q.push('P');
}
}
if (isPossible)
{
while (!q.empty())
{
cout << q.front();
q.pop();
}
}
else
{
cout << "impossible" << endl;
}
}