Design and analysis of the three -digit order of the three brute force methods, find the sum of the numbers and the product of the product EVANQINYI

2023-03-18  

1. The nine numbers of 1 to 9 form three three digits a, b, c, respectively, each number appears exactly once, requiring A: B: C = 1: 2: 3.
Requires to output all solutions in the format of “A B C” (three numbers are separated in one space), and one solution for each line; if there are multiple solutions, according to the value of the value of A

#include<iostream>
#include<cstring>
using namespace std;

class A{

public : 
       int a;
       int b;
       int c;
       int split();
};
int A::split()
{

    int ss[10];
    memset(ss,0,sizeof(ss));
    int sum=0;
ss [this-> a/100] = 1; // If the number is not repeated, the label in the array SS [1] ~ ss [9] must not repeat the number
    ss[this->a%100/10] = 1;
    ss[this->a%10]     = 1;
    ss[this->b/100]    = 1;
    ss[this->b%100/10] = 1;
    ss[this->b%10]     = 1;
    ss[this->c/100]    = 1 ;
    ss[this->c%100/10] = 1 ;
    ss[this->c%10]     = 1 ;
for (int i = 1; i <= 9; i ++) // Determine whether the numbers consisting of three three digits A, B, and C are repeated
    {

        sum += ss[i];
    }
if (SUM == 9) {// The number is not repeated, the output meets the results of the condition
        cout << this->a << ‘ ‘ << this->b << ‘ ‘ << this->c << endl;
    }
    sum=0;
    memset(ss,0,sizeof(ss));
    return 0;
}
int main()
{

    int i;
    A  digtal;
for (i = 123; I <= 329; I ++) // The smallest three -digit number is 123, the maximum 987/3 = 329, determine the traversal range
    {

        digtal.a=i,digtal.b=2*i,digtal.c=3*i;
        digtal.split();
    }
    return 0;
}

// Solution 2
#include<iostream>  
#include<cstdio>  
using namespace std;  
  
void split(int num, int &result_add, int &result_mul)  
{  
    int i, j, k;  
   
i = num/100; // Hundreds
j = num/10 % 10; // Ten bits
k = num % 10; // bit
   
result_add + = i + j + k; // The number of bits decomposed added
result_mul * = i * j * k; // multiplication
}  
  
int main()  
{  
    int i, j, k;  
    int result_add, result_mul;  
    for(i = 123; i <=329; i++)  
{// Each cycle, get 3 three -digit numbers, calculate the number and digital multiplication of the numbers containing
        j = i * 2;  
        k = i * 3;   
        result_add = 0;  
        result_mul = 1;  
        split(i, result_add, result_mul);  
        split(j, result_add, result_mul);  
        split(k, result_add, result_mul);  
if (result_add == 45 && result_mul == 362880) // Just only once appears
            printf(“%d %d %d\n”, i, j, k);  
    }  
    return 0;  
}  

2.

This question is too simple, so I won’t write it.

source

Random Posts

Back brush data shell script calls SQL script error reporting solution to the secret processing scheme synchronous digital warehouse data to HOLOGRES’s superior solution

C ++ 11 Thread First Test

Machine learning entry-liver disease prediction analysis

Luogu P1712 [noi2016] interval (line tree+greed+thinking)

CRON configuration detailed explanation 2 minutes 3 hours