Three Combo (Upgraded Version)--Luo Gu

P1618-Three Combo (Upgraded Version)
Title Description Divide the 9 numbers
1, 2, ..., 9 into three groups to form three three-digit numbers , and make the ratio of these three three-digit numbers A:B: C , try to find all three three-digit numbers that meet the conditions, if there is no solution, output No!!! . //Thank you Huang Xiao U Drink for perfecting the input format of the question meaning three numbers, A, B, C. Output format Several lines with 3 numbers per line. Sort in ascending order according to the first number of each line.




Input and output example:
Input #1:

1 2 3

Output #1

192 384 576
219 438 657
273 546 819
327 654 981

Violence works miracles, simple and rude.

#include <iostream>
using namespace std;
int zxgb(int x,int y,int z)
{
    
    
 int i;
 for(i=x;;i++)
 {
    
    
  if(i<y||i<z)
  continue;
  if(i%x==0&&i%y==0&&i%z==0)
  return i;
 }
}
int main()
{
    
    
 int d1,d2,d3,d4,d5,d6,d7,d8,d9,ans,sum=0,a,b,c,n;
 cin>>a>>b>>c;
 n=zxgb(a,b,c);
 for(d1=1;d1<=9;d1++)
 {
    
    
  for(d2=1;d2<=9;d2++)
  {
    
    
   if(d2==d1)
   continue; 
   for(d3=1;d3<=9;d3++)
   {
    
    
    if(d3==d1||d3==d2)
    continue;
    for(d4=1;d4<=9;d4++)
    {
    
    
     if(d4==d1||d4==d2||d4==d3)
     continue;
     for(d5=1;d5<=9;d5++)
     {
    
    
      if(d5==d1||d5==d2||d5==d3||d5==d4)
      continue;
      for(d6=1;d6<=9;d6++)
      {
    
    
        if(d6==d1||d6==d2||d6==d3||d6==d4||d6==d5)
        continue;
       for(d7=1;d7<=9;d7++)
       {
    
    
        if(d7==d1||d7==d2||d7==d3||d7==d4||d7==d5||d7==d6)
        continue;
        for(d8=1;d8<=9;d8++)
        {
    
    
         if(d8==d1||d8==d2||d8==d3||d8==d4||d8==d5||d8==d6||d8==d7)
         continue;
         for(d9=1;d9<=9;d9++)
         {
    
    
          if(d9==d1||d9==d2||d9==d3||d9==d4||d9==d5||d9==d6||d9==d7||d9==d8)
          continue;
          if((d1*100+d2*10+d3)*(n/a)==(d4*100+d5*10+d6)*(n/b)&&(d4*100+d5*10+d6)*(n/b)==(d7*100+d8*10+d9)*(n/c))
          {
    
    
           cout<<d1*100+d2*10+d3<<" "<<d4*100+d5*10+d6<<" "<<d7*100+d8*10+d9<<endl;
           sum++;
          }
         }
        }
       }
      }
     }
    }
   }
  }
 }
 if(sum==0)
 cout<<"No!!!";
 return 0;
}

Guess you like

Origin blog.csdn.net/HT24k/article/details/109271842