-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
55 lines (45 loc) · 1.07 KB
/
test.cpp
File metadata and controls
55 lines (45 loc) · 1.07 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, flag;
cin >> n;
deque<pair<int, int>> q;
for (int i = 1; i <= n; i++) {
int k;
cin >> k;
q.push_back(make_pair(i, k));
}
flag = q.front().second;
cout << q.front().first << ' ';
q.pop_front();
while (!q.empty()) {
if (flag > 0) {
for (int i = 0; i < flag - 1; i++) {
q.push_back(q.front());
q.pop_front();
}
flag = q.front().second;
cout << q.front().first << ' ';
q.pop_front();
}
else if (flag < 0) {
for (int i = 0; i > flag + 1; i--) {
q.push_front(q.back());
q.pop_back();
}
flag = q.back().second;
cout << q.back().first << ' ';
q.pop_back();
}
}
return 0;
}