chiaren @ 2019-09-28 14:37:11
#include<stdio.h>
#include<string.h>
#include<math.h>
int a,b,c,book[10],s[10];
int dfs(int step)
{
if(step==9)
{
int l,m,n;
l=s[1]*100+s[2]*10+s[3];
m=s[4]*100+s[5]*10*s[6];
n=s[7]*100+s[8]*10+s[9];
if(l*b==m*a&&m*c==n*b)
printf("%d %d %d\n",l,m,n);
return;
}
int i;
for(i=1;i<=9;i++)
{
if(book[i]==0)
{
book[i]=1;
s[step]=i;
dfs(step+1);
book[i]=0;
}
}
return;
}
int main()
{
scanf("%d%d%d",&a,&b,&c);
memset(book,0,sizeof(book));
dfs(0);
return 0;
}
by jxyzs @ 2019-09-28 14:38:53
@chiaren 显然,当第一次step等于9的时候不符合题意,你的step是变成10了,没有返回,一直往上加
by chiaren @ 2019-09-28 14:44:14
@[jxyzs](/space/show?uid=133922) 那我应该返回什么???
by OvOAuto @ 2019-09-28 14:53:28
if(step >= 9)
by OvOAuto @ 2019-09-28 14:54:03
@chiaren
by chiaren @ 2019-09-28 14:56:05
@OvO自动机 额 没用欸 还是没有输出
by mnbvcxzlkjhgfdsapoiu @ 2019-09-28 14:59:50
@chiaren 一看搜索就头晕
by chiaren @ 2019-09-28 15:00:25
@骷髅萨满 我已经晕了几天了。。。难过。。。
by OvOAuto @ 2019-09-28 15:01:14
@chiaren 码风太丑懒得看了再见
by Anyexyz @ 2019-10-16 22:15:15
@OvO自动机
码风整理,我也不想看了
#include <stdio.h>
#include <string.h>
#include <math.h>
int a, b, c, book[10], s[10];
int dfs(int step)
{
if (step == 9) {
int l, m, n;
l = s[1] * 100 + s[2] * 10 + s[3];
m = s[4] * 100 + s[5] * 10 * s[6];
n = s[7] * 100 + s[8] * 10 + s[9];
if (l * b == m * a && m * c == n * b)
printf("%d %d %d\n", l, m, n);
return;
}
int i;
for (i = 1; i <= 9; i++) {
if (book[i] == 0) {
book[i] = 1;
s[step] = i;
dfs(step + 1);
book[i] = 0;
}
}
return;
}
int main()
{
scanf("%d%d%d", &a, &b, &c);
memset(book, 0, sizeof(book));
dfs(0);
return 0;
}