编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#1696 #993. 汉诺塔问题 Compile Error 0 0 ms 0 K C / 651 B t330026070 2023-10-15 16:43:15
显示原始代码
#include <stdio.h>
int a[10] int main(int argc, char *argv[]) {
    for (int i = 0; i < 10; i++) {
        a[i] = 0;
    }
    int b;
    scanf("%d", &b);
    a[0] = 1;
    for (int i = 0; i < b; i++) {
        for (int j = 0; j < 10; j++) {
            a[j] = a[j] * 2;
            if (a[j] > 9999) {
                a[j + 1] = a[j] / 10000;
                a[j] = a[j] % 10000;
            }
        }
    }
    a[0]--;
    int p = 0;
    int p2 = 1;
    for (int i = 10; i >= 0; i--) {
        if (a[i] != 0)
            p = 1;
        if (p) {
            if ((a[j] > 999) || p2) {
                printf("%d", a[j]);
            } else if (a[j] > 99) {
                printf("0%d", a[j]);
            } else if (a[j] > 9) {
                printf("00%d", a[j]);
            } else {
                printf("000%d", a[j]);
            }
            p2 = 0;
        }
    }
    return 0;
}

编译信息

/sandbox/1/a.c:2:10: error: expected ';' after top level declarator
int a[10]
         ^
         ;
/sandbox/1/a.c:32:10: error: use of undeclared identifier 'j'
                        if((a[j]>999)||p2)      
                              ^
/sandbox/1/a.c:34:19: error: use of undeclared identifier 'j'
                                printf("%d",a[j]);
                                              ^
/sandbox/1/a.c:35:15: error: use of undeclared identifier 'j'
                        }else if(a[j]>99)
                                   ^
/sandbox/1/a.c:37:20: error: use of undeclared identifier 'j'
                                printf("0%d",a[j]);
                                               ^
/sandbox/1/a.c:38:15: error: use of undeclared identifier 'j'
                        }else if(a[j]>9)
                                   ^
/sandbox/1/a.c:40:21: error: use of undeclared identifier 'j'
                                printf("00%d",a[j]);
                                                ^
/sandbox/1/a.c:43:22: error: use of undeclared identifier 'j'
                                printf("000%d",a[j]);
                                                 ^
8 errors generated.