-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeincrease.cpp
71 lines (65 loc) · 896 Bytes
/
deincrease.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
using namespace std;
struct node{
node* nxt;
int val;
node(){
nxt = NULL;
val = 0;
}
node(int _v){
val = _v;
nxt = NULL;
}
};
class sol{
node* dummy;
node* last;
node* cur;
public:
sol(){
dummy = new node();
dummy->nxt = new node(1);
cur = dummy;
last = cur;
}
~sol(){
while(dummy){
cur =dummy->nxt;
delete dummy;
dummy = cur;
}
}
void solver(string s){
int i = 2;
while(i < s.length()+2){
node* tmp = new node(i);
if(s[i-2] == 'i'){
cur->nxt->nxt = tmp;
cur = cur->nxt;
last = cur;
}else{
tmp->nxt = last->nxt;
last->nxt = tmp;
if(last==cur)cur=cur->nxt;
}
i++;
}
}
void displace(){
node* tmp = dummy->nxt;
while(tmp){
cout<<tmp->val<<" ";
tmp = tmp->nxt;
}
cout<<endl;
}
};
int main(){
string s;
while(cin>>s){
sol ss;
ss.solver(s);
ss.displace();
}
}