結果

問題 No.401 数字の渦巻き
ユーザー monburan_0401monburan_0401
提出日時 2018-09-22 19:45:09
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,542 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 29,324 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 14:51:30
合計ジャッジ時間 1,953 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 0 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 0 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 0 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 0 ms
4,376 KB
testcase_24 AC 0 ms
4,376 KB
testcase_25 AC 0 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 0 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
int main(void){
    int N;
    int box[30][30] = {0};
    int count = 1;

    scanf("%d",&N);

    int start = 0;
    int end = N;

    /*
    //  left to right
    for(int i = 0; i < N; i++){
        box[0][i] = count;
        count++;
    }
    
    //  douwn
    for(int j = 1; j < N; j++){
        box[j][N-1] = count;
        count++;
    }
    
    //  right to left
    for(int k = N-2; k >= 0; k--){
        box[N-1][k] = count;
        count++;
    }
    
    //  up
    for(int l = N-2; l >= 1; l--){
        box[l][0] = count;
        count++;
    }
    */
   while(count <= N*N){
        //  left to right
        for(int i = start; i < end; i++){
            box[start][i] = count;
            count++;
        }
    
        //  douwn
        for(int j = start + 1; j < end; j++){
            box[j][end-1] = count;
            count++;
        }
    
        //  right to left
        for(int k = end-2; k >= start; k--){
            box[end-1][k] = count;
            count++;
        }
    
        //  up
        for(int l = end-2; l >= start+1; l--){
            box[l][start] = count;
            count++;
        }
        start++;
        end--;
   }
   
    //  check
    for(int a = 0; a < N; a++){
        for(int b = 0; b < N; b++){
            if(box[a][b] / 100 == 0){
                printf("0");
                if(box[a][b] / 10 == 0){
                    printf("0");
                }
            }
            printf("%d ",box[a][b]);
        }
        printf("\n");
    }

    return 0;
}
0