有3个数,将这3个数的每位分离出来正好表示从1-9这9个数字且不重复,如果将这3个数按一定次序排,那么后

1个回答

  • int check(int value,unsigned char *mark)

    {

    #define MARK(x,mark) {if(x == 0) return 1; if(mark[x - 1] == 1) return 1; mark[x-1] = 1;}

    int x;

    x = value % 10;

    MARK(x,mark);

    if(value > 9)

    {

    x = value / 10 % 10;

    MARK(x,mark);

    }

    if(value > 99)

    {

    x = value / 100 % 10;

    MARK(x,mark);

    }

    return 0;

    }

    main()

    {

    int f,s;

    unsigned char mark[9] = {0};

    for(f = 0;f < 1000 ;f ++)

    {

    memset(mark,0,sizeof(mark));

    if(check(f,mark)) continue;

    s = f + 333;

    if(check(s,mark))continue;

    s += 333;

    if(check(s,mark)) continue;

    for(s = 0; s < 9; s ++)

    if(mark[s] == 0) break;

    if(s == 9)

    printf("find value %d %d %dn",f,f + 333,f + 666);

    }

    }

    运行最终结果

    find value 123 456 789

    find value 132 465 798

    find value 213 546 879

    find value 231 564 897

    find value 312 645 978

    find value 321 654 987