除了枚举法还能做出吗

img

img

#include<stdio.h>
int main(void) {
    int x,n;
    scanf("%d",&n);
    for (x=0; x<16; x++ ) {
        int v = 123;
        char c1, c2, c3, c4;
        c1 = x & 8 ? '+' : '-';
        if ( x & 8 ) v += 45;
        else v -= 45;
        c2 = x & 4 ? '+' : '-';
        if ( x &4 ) v += 67;
        else v -= 67;
        c3 = x & 2 ? '+' : '-';
        if ( x & 2) v+= 8;
        else v -= 8;
        c4 = x & 1 ? '+' : '-';
        if ( x & 1) v+= 9;
        else v -= 9;
        if ( v == n ) {
            printf("123%c45%c67%c8%c9=%d", c1, c2, c3, c4,n);
            return 0;
        }
    }
    printf("impossible");
    return 0;
}


 觉得有用的话采纳一下哈