-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path1416.cpp
More file actions
83 lines (83 loc) · 1.22 KB
/
1416.cpp
File metadata and controls
83 lines (83 loc) · 1.22 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
#include<iostream>
#include<cstring>
using namespace std;
int num[7]={0},a[7]={0},lim,mem[7]={0};
int maxnum,rp;
void deal(int k,int n)
{
int s=0,temp[7],i,j,m=1;
for(i=1;i<=k;i++)
{
temp[i]=0;
for(j=1;j<=num[i];j++)
{
temp[i]*=10;
temp[i]+=a[m];
m++;
}
s+=temp[i];
//cout<<temp<<' ';
}
//cout<<s<<endl;
if(s==maxnum)rp++;
if(s>maxnum&&s<=lim)
{
for(i=1;i<=n;i++)
mem[i]=i<=k?temp[i]:-1;
maxnum=s;
rp=0;
}
}
void ss(int n,int i,int k,int s)
{
int j,q;
if(s>=n)return;
if(i==k)
{
num[k]=n-s;
//for(j=1;j<=k;j++)
// cout<<num[j];
//cout<<' '<<s<<endl;
deal(k,n);
return;
}
if(i<k)
{
for(j=1;j<=n;j++)
{
num[i]=j;
s=0;
for(q=1;q<=i;q++)
s+=num[q];
ss(n,i+1,k,s);
}
}
}
int main()
{
int i,j,n;
char c[7];
while(cin>>lim>>c)
{
maxnum=rp=0;
n=strlen(c);
if(lim==0)return 0;
for(i=1;i<=n;i++)
a[i]=int(c[i-1]-48);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
num[j]=0;
ss(n,1,i,0);
}
if(rp>=1)cout<<"rejected\n";
else if(maxnum==0)cout<<"error\n";
else
{
cout<<maxnum;
for(i=1;i<=n;i++)
if(mem[i]>=0)cout<<' '<<mem[i];
cout<<endl;
}
}
}