#include<cstdio>
using
namespace
std;
int
n;
bool
shuchu=0;
bool
cha(
int
i,
int
j)
{
bool
ji[11]={0};
if
(i>=10&&i/10!=i%10&&i/10!=0&&i%10!=0)
{
ji[i/10]=1;
ji[i%10]=1;
}
if
(i>=10&&(i/10==i%10||i/10==0||i%10==0))
return
1;
if
(i<10)
{
ji[i]=1;
}
int
jii=j*(n-i);
while
(jii)
{
if
(ji[jii%10]==1||jii%10==0)
{
return
1;
}
ji[jii%10]=1;
jii/=10;
}
while
(j)
{
if
(ji[j%10]==1||j%10==0)
return
1;
ji[j%10]=1;
j/=10;
}
for
(
int
i=1;i<10;i++)
{
if
(ji[i]==0)
return
1;
}
return
0;
}
int
weishu(
int
k)
{
int
jii=0;
while
(k!=0)
{
jii++;k/=10;
}
return
jii;
}
int
printt(
int
k)
{
int
jii=weishu(k);
for
(
int
i=0;i<jii;i++)
{
printf
(
"-"
);
}
printf
(
"\n"
);
return
jii;
}
void
print(
int
shu,
int
zhi)
{
int
jishu=3;
if
(n==100)
jishu++;
if
(n<10)
jishu--;
if
(shu>=10)
{
jishu++;
}
if
(zhi>=10)
{
jishu++;
}
for
(
int
i=0;i<jishu;i++)
{
printf
(
" "
);
}
printf
(
"%d\n"
,(n-shu)*zhi);
printf
(
"%d=%d"
,n,shu);
int
jish=printt((n-shu)*zhi);
int
jjshu=weishu(zhi);
for
(
int
i=0;i<jish+jishu-jjshu;i++)
{
printf
(
" "
);
}
printf
(
"%d\n"
,zhi);
}
void
fen()
{
for
(
int
i=1;i<n;i++)
{
for
(
int
j=1;j<5000;j++)
{
if
(cha(i,j)==0)
{
shuchu=1;
print(i,j);
}
}
}
}
int
main()
{
scanf
(
"%d"
,&n);
while
(n!=0)
{
shuchu=0;
fen();
if
(shuchu==0)
{
printf
(
"impossible\n"
);
}
scanf
(
"%d"
,&n);
}
}
原文:https://www.cnblogs.com/fanhao050109/p/11197323.html