1299: 排列

題目

Description

用1,2,3,4,5,6,7,8,9組成三個三位數abc def ghi每一個數字恰好用一次,要求滿足abc:def:ghi=1:2:3輸出所有解
Input


Output

用1,2,3,4,5,6,7,8,9組成三個三位數abc def ghi每一個數字恰好用一次,要求滿足abc:def:ghi=1:2:3輸出所有解
Sample Input


Sample Output

192 384 576
….
後面還有多組,這裏省略了


代碼塊

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        for(int i = 123;i<330;i++){
            int[] a = new int[10];
            Arrays.fill(a, 0);
            int n = 2*i;
            int m = 3*i;
            int k = i;
            while(k>0){
                ++a[k%10];
                k/=10;
            }
            while(n>0){
                ++a[n%10];
                n/=10;
            }
            while(m>0){
                ++a[m%10];
                m/=10;
            }
            if(a[0]!=0) continue;
            boolean flag = false;
            for(int j = 0;j<10;j++){
                if(a[j]>1){
                    flag = true;
                    break;
                }
            }
            if(flag) continue;
            else System.out.println(i+" "+2*i+" "+3*i);
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章