[ACM]用1,2,3...9组成3个三位数abc, def, ghi, 每个数字恰好使用一次,且abc:def:ghi=1:2:3,输出所有解。

来源:互联网 发布:电脑安装软件需要密码 编辑:程序博客网 时间:2024/04/27 19:59

////  main.c//  test#include <stdio.h>#include <string.h>//#define LOCALint main(int argc, const char * argv[]){    #ifdef LOCAL    freopen("data.in", "r", stdin);    freopen("data.out", "w", stdout);#endif        //用1,2,3...9组成3个三位数abc, def, ghi, 每个数字恰好使用一次,且abc:def:ghi=1:2:3,输出所有解。    int n, i, j;    char a[10];    for(n = 123; n < 330; n++){        sprintf(a, "%d", n * 1000000 + n * 2 * 1000 + n * 3);                for(j = 0, i = '1'; i <= '9'; memchr(a, i++, 9) && j++);                if (j == 9) {            printf("%d %d %d \n", n, n * 2, n * 3);        }    }return 0;}

原创粉丝点击