forked from Phon1209/Competitive_Programming_SourceCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlowcom3.cpp
More file actions
103 lines (103 loc) · 2.36 KB
/
lowcom3.cpp
File metadata and controls
103 lines (103 loc) · 2.36 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
94
95
96
97
98
99
100
101
102
103
#include<bits/stdc++.h>
using namespace std;
#define sint(a) int a; scanf("%d",&a);
#define sint2(a,b) int a,b; scanf("%d %d",&a,&b);
#define sint3(a,b,c) int a,b,c; scanf("%d %d %d",&a,&b,&c);
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b);
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define mkp make_pair
#define pb push_back
#define inf INT_MAX
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sdouble(a) double a; scanf("%lf",&a);
#define slong(a) long long a; scanf("%lld",&a);
#define sstring(a,x) char a[x]; scanf("%s",a);
#define sss(a,b,c) stringstream a; a<<b; a>>c
#define rev(s) reverse(all(s));
#define FOR(a,b,c) for(int a=b;a<c;a++)
#define ROF(a,b,c) for(int a=b;a>c;a--)
#define pause system("pause")
#define endl printf("\n")
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
vector<string> v;
bool lowcom(int n,int k)
{
v.pb("ONE X");
int cnt=0;
stack<int> st;
while(n!=0)
{
int tmp=n%k;
while(tmp--)
{
v.pb("PUH X");
cnt++;
n--;
st.push(1);
}
if(n==0)break;
for(int i=0;i<k;i++)
v.pb("PUH X");
cnt+=k;
for(int i=1;i<k;i++)
v.pb("ADD");
cnt+=k-1;
st.push(1);
n/=k;
if(n==0 || n==1)break;
v.pb("POP X");
cnt++;
st.pop();
}
st.pop();
while(!st.empty())
{
st.pop();
cnt++;
v.pb("ADD");
}
v.pb("POP X");
v.pb("PRN X");
cnt+=2;
if(cnt<=40)
{
return false;
}
else return true;
}
int main()
{
int n;
// freopen("test.txt","w",stdout);
// freopen("IN.txt","r",stdin);
while(int1(n)!=EOF)
{
if(n==0)
{
printf("ZER X\n");
printf("PRN X\n");
continue;
}
if(n==1)
{
printf("ONE X\n");
printf("PRN X\n");
continue;
}
for(int i=2;i<=30;i++)
{
v.clear();
if(lowcom(n,i))break;
}
for(int i=0;i<v.size();i++)
{
printf("%s\n",v[i].c_str());
}
}
}