递归!!!!!!!!!!
2024-06-19 14:37:37
发布于:湖北
9阅读
0回复
0点赞
还是递归,和三连击那个差不多
就是判断比例的地方差不多
#include <bits/stdc++.h>
using namespace std;
int nums[] = {0,1,2,3,4, 5,6,7,8,9};
int zw[] = {0,0,0,0,0, 0,0,0,0,0};
int A,B,C;
int t=0;
void slj(int n,string s)
{
if(n==9)
{
int n1 = (s[0]-'0')*100 + (s[1]-'0')*10 + (s[2]-'0');
int n2 = (s[3]-'0')*100 + (s[4]-'0')*10 + (s[5]-'0');
int n3 = (s[6]-'0')*100 + (s[7]-'0')*10 + (s[8]-'0');
if (n1*B == n2*A and n2*C == n3*B)
{
cout<<n1<<" "<<n2<<" "<<n3<<endl;
t=1;
}
}
else{
for(int i=1;i<=9;i++)
{
if(zw[i]==0)
{
zw[i] = 1;
slj(n**** + char('0'+nums[i]));
zw[i] = 0;
}
}
}
}
int main()
{
cin>>A>>B>>C;
slj(0,"");
if(t==0)cout<<"No!!!";
return 0;
}
这里空空如也
有帮助,赞一个