-
Notifications
You must be signed in to change notification settings - Fork 0
/
RMID.cpp
50 lines (47 loc) · 1.01 KB
/
RMID.cpp
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
#include <iostream>
using namespace std;
int main () {
int n;
int arr1[100001];
int arr2[100001];
int index1, index2, bottom2, nbArr1, nbArr2;
index1 = -1; index2 = -1; bottom2 = 0; nbArr1 = 0; nbArr2 = 0;
while (scanf ("%d",&n) != EOF) {
if (n == 0) {
printf("\n");
index1 = -1; index2 = -1; bottom2 = 0; nbArr1 = 0; nbArr2 = 0;
}
else if (n == -1) {
printf("%d\n", arr1[index1]);
index1 = index1 - 1;
nbArr1 --;
if (nbArr1 < nbArr2) {
nbArr1 ++;
nbArr2 --;
index1++;
arr1[index1] = arr2[bottom2];
bottom2 ++;
}
}
else {
if (nbArr1 == 0 && nbArr2 == 0) {
nbArr1 ++;
index1 ++;
arr1[index1] = n;
}
else if (nbArr1 > nbArr2) {
nbArr2 ++;
index2 ++;
arr2[index2] = n;
}
else {
nbArr1 ++;
index1 ++;
arr1[index1] = arr2[bottom2];
bottom2 ++;
index2 ++;
arr2[index2] = n;
}
}
}
}