PTA: trifecta (15 minutes) (C language)

This entitled to submit answers to questions, you can write a program or a hand count after calculate the answer, answer directly to the text on the machine, also can submit answers generator.

The 1,2, ..., 9 9 number divided into three groups, each consisting of three digits 3 and 3 so that these constitute a three-digit number: 2: 3 ratio, satisfy all the conditions to obtain test 3 triple digits.

Input formats:
wood input

Output format:
a plurality of rows of three numbers. Each row arranged in a numerical order.

Sample input:
None

Sample output:
192 384 576


#include <stdio.h>

int judge(int a, int b, int c);

int main()
{
    int a, b, c;
    for (a = 123; a <= 333; a++)
    {
        b = a*2;
        c = a*3;
        if(judge(a, b, c))
            printf("%d %d %d\n", a, b, c);
    }

    return 0;
}
int judge(int a, int b, int c)
{
    int ok = 1;
    int ch[10] = {0};
    while(a)
    {
        ch[a%10]++;
        a /= 10;
    }
     while(b)
    {
        ch[b%10]++;
        b /= 10;
    }
     while(c)
    {
        ch[c%10]++;
        c /= 10;
    }
    for (int i = 1; i <= 9; i++)
    {
        if (ch[i] == 0)
            ok = 0;
    }
    
    return ok;
}
Published 58 original articles · won praise 21 · views 601

Guess you like

Origin blog.csdn.net/qq_45624989/article/details/105399630