#include <stdio.h>
#include <stdlib.h>
void test(int* seq, int* rec, int now, int step, int* use);
int main()
{
int seq[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int rec[10], use[10] = {0};
test(seq, rec, 0, 0, use);
return 0;
}
void test(int* seq, int* rec, int now, int step, int* use)
{
int i, j;
if(step == 10)
{
if(rec[1]*10000+rec[4]*1000+rec[5]*100+rec[7]*10+rec[9] + 2*(rec[7]*100+rec[0]*10+rec[3]) == rec[6]*10000+rec[2]*1000+rec[8]*100+rec[7]*10+rec[9])
printf("%d%d%d%d%d + %d%d%d + %d%d%d = %d%d%d%d%d\n", rec[1], rec[4], rec[5], rec[7], rec[9], rec[7], rec[0], rec[3] , rec[7], rec[0], rec[3], rec[6], rec[2], rec[8], rec[7], rec[9]);
}
else
{
for(i = 0; i < 10; i++)
{
if(!use[i])
{
rec[step] = seq[i];
use[i] = 1;
test(seq, rec, i, step+1, use);
use[i] = 0;
}
}
}
return;
}