[P1008] Luo Valley trifecta solving report

Topic background

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.

Title Description

The 1,2, \ cdots, 91,2, ⋯, 9 99 total number of 33 different groups, each consisting of three digits 33, 33 and so that three-digit number composed of 1: 2: 31: 2: 3 ratio, satisfy the conditions of the test to obtain all three digits 33.

Input Format

Wood input

Output Format

Several lines of 33 digits. Each row arranged in ascending numerical order 11.

Sample input and output

Input # 1 copy

no

Output # 1 copy

192 384 576 
* * * 
... 

* * * 
(output being harmonized)

answer

Because 329 * 3 = 987, so that the minimum three digits from 123 to 329 traversed. flag array do nine digital sign, if there are numbers to repeat the words, flag array 9 figures and will be less than 9, or print three three digits.

#include <cstdio>
#include <string.h>
int main()
{
    int flag[10];//9个数字的标志
	int s[3];//3个三位数
	int i, j, k;
    for(s[0] = 123; s[0] <= 329; s[0]++){
        memset(flag, 0, 10 * sizeof(int));//初始化置零
        s[1] = s[0] * 2;
        s[2] = s[0] * 3;
        for(i = 0; i < 3; i++){
            flag[s[i] / 100] = 1;//百位数
            flag[(s[i] / 10) % 10] = 1;//十位数
            flag[s[i] % 10] = 1;//个位数
            k = 0;
            for(j = 1; j < 10; j++){
            	k = k + flag[j];
			}
        }
        if(k == 9){
        	printf("%d %d %d\n", s[0], s[1], s[2]);
		}
    }
	return 0;
}

 

Published 81 original articles · won praise 94 · views 30000 +

Guess you like

Origin blog.csdn.net/wyatt007/article/details/104064755