题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
1 ~ 9的数字可以组成 3 个 3 位数,设为:A,B,C, 现在要求满足如下关系:
B=2∗A
C=3∗A
请你输出 AA 的所有可能答案,数字间用空格分开,数字按升序排列。
关键:用到了全排列函数
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int s[9]={1,2,3,4,5,6,7,8,9};
do
{
int A=s[0]*100+s[1]*10+s[2]*1;
int B=s[3]*100+s[4]*10+s[5]*1;
int C=s[6]*100+s[7]*10+s[8]*1;
if(B==2*A&&C==3*A) cout<<A<<" ";
}while(next_permutation(s,s+9));
return 0;
}