- import java.util.Scanner;
- //将 1-9 共9个数分成3组,分别组成3个三位数,且使这3个三位数构成A:B:C的比例,试求出所有满足条件的3个三位数。不满足输出“No!!!”。
- public class Main {
-
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int a = sc.nextInt();
- int b = sc.nextInt();
- int c = sc.nextInt();
- int count = 0;
- for (int i = 123; i <=333; i++) {
- int A = a * i;
- int B = b * i;
- int C = c * i;
- //ABC个,十,百位分别相加=1+2+3+4+5+6+7+8+9&&ABC个,十,百位相乘=1*2*3*4*5*6*7*8*9
- boolean flag=(A / 100 + A / 10 % 10 + A % 10 + B / 100 + B / 10 % 10 + B % 10 + C / 100 + C / 10 % 10 + C % 10 == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 )
- &&((A / 100) *(A / 10 % 10) * (A % 10 )* (B / 100 )* (B / 10 % 10 )* (B % 10 )* (C / 100) *(C / 10 % 10) * (C % 10) == 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9);
- if (flag) {
- count++;
- System.out.println(A+" "+B+" "+C);
- }
- }
- if (count == 0) {
- System.out.println("No!!!");
- }
- }
- }