Title Description Description
1,2,...,9 a total of 9 divided into three groups, respectively, composed of three three digits, and make the three three-digit ratio of A:B:C, try to find out all the conditions of three three digits, if there is no solution, output "no!!!".
input/output format input/output
Input Format:
Three numbers, a B C.
output Format:
Several lines, 3 digits per line. In ascending order of the first number in each row.
input and Output sample sample Input/output
sample Test point # #
Input Sample:
1 2 3
Sample output:
192 384 576
219 438 657
273 546 819
327 654 981
DescriptionDescription
Guaranteed A<b<cIdea: from (1~1000/c) cycle, and then proportional assignment, each digit into an array of each bit, to determine how many numbers have been used, if there are 9 (that is, just run out), the output can be
Tip: Remember to determine whether the proportional assignment is more than 1000, beyond the jump canThe
code is as follows:
1#include <iostream>2 using namespacestd; 3 intMain ()4 { 5 inta,b,c,x[9],a1,a2,a3; 6 inty=0, ans=0, flag[Ten]={0},i,j;//is the flag statistic used ?7cin>>a1>>a2>>a3;//input8 for(j=1; j<= +/a3;j++) 9 { Teny=0; One for(i=0;i<9; i++) Aflag[i]=0;//Full return 0 -A=a1*J; -B=a2*j;//Assigning values proportionally thec=a3*J; - if(a>= +|| B> +|| C> +) - Break;//out of range situation - /*=================================*/ +x[0]=a/ -; -x[1]= (A/Ten)%Ten; +x[2]=a%Ten; Ax[3]=b/ -; atx[4]= (b/Ten)%Ten;//put each digit into the array -x[5]=b%Ten; -x[6]=c/ -; -x[7]= (c/Ten)%Ten; -x[8]=c%Ten; - /*=================================*/ in for(i=0;i<9; i++) -flag[x[i]-1]=1;//statistic used number (used to become 1) to for(i=0;i<9; i++) +Y+=flag[i];//How many statistics have been used - if(y==9)//if y=9, it means that all the numbers have been used, the output the { *cout<<a<<" "<<b<<" "<<c<<Endl; $ans++;//A b c,ans that satisfies is not equal to 0.Panax Notoginseng } - } the if(!ans)//not satisfied, Output no!!! +cout<<"No!!!"; A}
Rokua-Triple Combo (upgrade)-boss War-Getting started comprehensive Exercise 1