/*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NB_NOMBRES (31)
char
*nombres[NB_NOMBRES]=
{
"ZERO",
"UN",
"ET",
"DEUX",
"TROIS",
"QUATRE",
"CINQ",
"SIX",
"SEPT",
"HUIT",
"NEUF",
"DIX",
"ONZE",
"DOUZE",
"TREIZE",
"QUATORZE",
"QUINZE",
"SEIZE",
"TRENTE",
"QUARANTE",
"CINQUANTE",
"SOIXANTE",
"VINGT",
"VINGTS",
"CENT",
"CENTS",
"MILLE",
"MILLION",
"MILLIONS",
"MILLIARD",
"MILLIARDS"
};
#define MAX_LEFT 7
//#define MAX_RIGHT 10
int
numbers[1000];
int
used[NB_NOMBRES];
int
alpha[256];
int left;
void RecurseRight(int depth,
int start)
{
int
n;
for (n =
'A';n<='Z';++n)
{
if
(alpha[n]) break;
}
if (n > 'Z')
{
FILE *out;
out = fopen("S.TXT",
"at");
for (n =
0;n < left;++n)
{
if
(n)
{
printf("+");
fprintf(out, "+");
}
printf("%s",
nombres[numbers[n]]);
fprintf(out, "%s",
nombres[numbers[n]]);
}
for (n = left;n < depth;++n)
{
printf("-");
fprintf(out, "-");
printf("%s",
nombres[numbers[n]]);
fprintf(out, "%s",
nombres[numbers[n]]);
}
printf("\n");
fprintf(out,
"\n");
fclose(out);
}
for (n = start;n < NB_NOMBRES-8;++n)
{
if (used[n] <= 0)
{
int valid;
char
*p;
// we can use the number
numbers[depth]
= n;
--used[n];
valid = 1;
p = nombres[n];
while(*p)
{
if (--alpha[*p]
< 0) valid = 0;
++p;
}
if (valid)
{
RecurseRight(depth+1, n+1);
}
p = nombres[n];
while(*p)
{
++alpha[*p];
++p;
}
++used[n];
}
}
}
void RecurseLeft(int depth,
int start)
{
int
n;
if (depth > 0)
{
left = depth;
RecurseRight(depth, 0);
//RecurseRight(depth, numbers[0]+1);
}
if (depth >= MAX_LEFT) return;
for (n = start;n < NB_NOMBRES;++n)
{
if (used[n] >= 0)
{
char
*p;
// we can use the number
numbers[depth]
= n;
++used[n];
p = nombres[n];
while(*p)
{
++alpha[*p];
++p;
}
RecurseLeft(depth+1, n+1);
p = nombres[n];
while(*p)
{
if (--alpha[*p]
< 0) _asm int 3;
++p;
}
--used[n];
}
}
}
int
main()
{
int
i;
for(i=0;i<NB_NOMBRES;++i)
used[i] = 0;
for(i=0;i<256;++i)
alpha[i] = 0;
RecurseLeft(0, 0);
return 0;
}