-
Notifications
You must be signed in to change notification settings - Fork 0
/
2570_ShreddingCompany.cc
128 lines (109 loc) · 1.86 KB
/
2570_ShreddingCompany.cc
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
*
* Author : fcbruce <fcbruce8964@gmail.com>
*
* Time : Sun 22 May 2016 15:25:20
*
*/
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;
typedef long long LL;
typedef int itn;
const int maxn = 0;
const int maxm = 0;
int limit, number;
int sum, count, max;
std::stack<int> st, res_st;
void print()
{
printf("%d", max);
while (!res_st.empty())
{
printf(" %d", res_st.top());
res_st.pop();
}
puts("");
}
inline int reverse(std::stack<int> temp)
{
int result = 0;
while (!temp.empty())
{
result = result * 10 + temp.top() % 10;
temp.pop();
}
return result;
}
void dfs(int number)
{
if (sum > limit) return;
if (number == 0)
{
if (sum == max)
{
count++;
res_st = st;
}
else if (sum > max)
{
count = 1;
max = sum;
res_st = st;
}
return ;
}
std::stack<int> temp;
while (number)
{
temp.push(number % 10);
number /= 10;
int rev = reverse(temp);
sum += rev;
st.push(rev);
dfs(number);
st.pop();
sum -= rev;
}
}
int main()
{
#ifdef FCBRUCE
freopen("/home/fcbruce/code/t", "r", stdin);
#endif // FCBRUCE
while (scanf("%d%d", &limit, &number) == 2 && (limit || number))
{
count = 0;
max = -1;
sum = 0;
while (!st.empty()) st.pop();
dfs(number);
if (count == 0) puts("error");
if (count > 1) puts("rejected");
if (count == 1) print();
}
return 0;
}