P1618 trifecta (upgrade version) attached to resolve

Title Description
will be 1, 2, ..., 9 9 number into three groups, each consisting of three three-digit number, and that the three three-digit ratio is A: B: C, again determined to satisfy all the conditions three three digits, if no solution, output No !!!.

Input format
three numbers, A, B, C.

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

I must first determine a first number of 111 to 333, and then can calculate whether A i is divisible, if it can be scaled output j, k, and the number of each bit determines whether the removed all included 123456789, so that the time complexity to multiple loops smaller than.

If there is no set of data needs to meet the requirements of the test variable, test = 0, it outputs a set of test ++, so that at the end of the test to determine the size can decide whether the output No !!!.

#include<stdio.h>
int main(){
	int te[9]={1,2,3,4,5,6,7,8,9},what=0,num[9];
	int judge=0,test=0,a,b,c,i,j,k,x=0,y=0;
	scanf("%d%d%d",&a,&b,&c);
	for(i=123;i<=333;i++){
		if(i%a!=0){
			continue;
		}
		what=0;
		j=i/a*b;
        k=i/a*c;
        num[0]=i/100;num[1]=i%100/10;num[2]=i%10;num[3]=j/100;num[4]=j%100/10;num[5]=j%10;num[6]=k/100;num[7]=k%100/10;num[8]=k%10;
        for(x=0;x<9;++x){
        	for(y=0;y<9;++y){
        		if(te[x]==num[y]){
        			what++;break;
				}
			}
		}
		if(what==9){
			printf("%d %d %d\n",i,j,k);
			test++;
		}
	}
	if(test==0){
		printf("No!!!\n");
	}
	return 0;
}
Published 36 original articles · won praise 29 · views 1026

Guess you like

Origin blog.csdn.net/bupt_sanqing/article/details/104709842