编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#4582 #1022. 相等步数 Compile Error 0 0 ms 0 K C / 806 B t330026028 2024-01-17 14:28:56
显示原始代码
#include <stdio.h>
int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    int time[10] = { 0 };
    int min;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < n; j++) {
            if (a[j] % 10 != i) {
                if (i < a[j] % 10) {
                    time[i] += 10 + i - (a[j] % 10);
                }
                if (i > a[j] % 10) {
                    time[i] += i - (a[j] % 10);
                }
                if (i = a[j] % 10) {
                    time[i] += 10;
                }
            }
        }
        min = time[0];
        for (int i = 1; i < 10; i++) {
            if (min >= time[i]) {
                min = time[i];
            }
        }
        printf("%d ", min);

        return 0;
    }

编译信息

/sandbox/1/a.c:21:23: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
                if( i = a[j] % 10){
                    ~~^~~~~~~~~~~
/sandbox/1/a.c:21:23: note: place parentheses around the assignment to silence this warning
                if( i = a[j] % 10){
                      ^
                    (            )
/sandbox/1/a.c:21:23: note: use '==' to turn this assignment into an equality comparison
                if( i = a[j] % 10){
                      ^
                      ==
/sandbox/1/a.c:38:1: error: expected '}'
^
/sandbox/1/a.c:3:1: note: to match this '{'
{
^
1 warning and 1 error generated.