forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1117 - Pairs of integers.cpp
executable file
·73 lines (51 loc) · 1.15 KB
/
1117 - Pairs of integers.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
72
73
#include <cstdio>
#include <set>
using namespace std;
int d[9],cont,M,x;
set<int> S;
void search(int n){
if(n%11<10){
x=10*(n/11)+(n%11);
for(int i=cont-1;i>=0;i--) x=10*x+d[i];
S.insert(x);
}
if(n%2==0 && n>0){
int d1=(n%10)/2;
int d2=d1+5;
cont++;
if(n>2*d1){
d[cont-1]=d1;
search((n-d1)/10);
}
if(n>2*d2){
d[cont-1]=d2;
search((n-d2)/10);
}
cont--;
}
}
int dig(int n){
if(n==0) return 1;
cont=0;
while(n!=0){
n/=10;
cont++;
}
return cont;
}
int main(){
int N;
scanf("%d",&N);
cont=0;
search(N);
int sz=S.size(),aux;
set<int> :: iterator it;
printf("%d\n",sz);
for(it=S.begin();it!=S.end();it++){
aux=(*it);
printf("%d + ",aux);
for(int j=dig(aux)-dig(N-aux)-1;j>0;j--) printf("0");
printf("%d = %d\n",N-aux,N);
}
return 0;
}