-
Notifications
You must be signed in to change notification settings - Fork 0
/
day22-1.cpp
60 lines (46 loc) · 1004 Bytes
/
day22-1.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
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("aoc.in");
ofstream fout("aoc.out");
int v[10007],w[10007],n,i,j,x;
char c;
/**
replacements:
s-deal into new stack
c-cut
i-deal with increment
**/
int main(){
n=10007;
for(i=0;i<n;i++)
v[i]=i;
while(fin>>c){
if(c=='s'){
for(i=0;i<n;i++)
w[n-1-i]=v[i];
}
if(c=='c'){
fin>>x;
if(x<0)
x=n+x;
for(i=x,j=0;i<n;i++,j++)
w[j]=v[i];
for(i=0;i<x;i++,j++)
w[j]=v[i];
}
if(c=='i'){
fin>>x;
for(i=0,j=0;i<n;i++,j=(j+x)%n)
w[j]=v[i];
}
for(i=0;i<n;i++)
v[i]=w[i];
}
// for(i=0;i<n;i++)
// cout<<v[i]<<" ";
for(i=0;i<n;i++)
if(v[i]==2019)
cout<<i;
return 0;
}