結果

問題 No.401 数字の渦巻き
ユーザー mban259mban259
提出日時 2016-08-02 18:30:10
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,205 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 107,520 KB
実行使用メモリ 18,048 KB
最終ジャッジ日時 2024-04-24 15:08:24
合計ジャッジ時間 2,550 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class A {
    static int N;
    static int[,] Q;
    static int Dir = 0;
    static int[] Pos = new int[2];
    static void Main() {
        N = int.Parse(Console.ReadLine());
        Q = new int[N, N];
        for(int i = 1; i <= N * N; i++) {
            Q[Pos[0], Pos[1]] = i;
            Next();
        }
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N - 1; j++) {
                Console.Write(string.Format("{0:D4}", Q[j,i]));
                Console.Write(" ");
            }
            Console.Write(string.Format("{0:D4}", Q[N-1,i]));
            Console.WriteLine();
        }
    }
    static void Next() {
        switch (Dir) {
            case 0:
                if (Pos[0] < N-1) {
                    if (Q[Pos[0] + 1, Pos[1]]!=0) {
                        Dir = 1;
                        Pos[1]++;
                    }
                    else {
                        Pos[0]++;
                    }
                }
                else {
                    Dir = 1;
                    Pos[1]++;
                }
                break;
            case 1:
                if (Pos[1] < N-1) {
                    if (Q[Pos[0], Pos[1] + 1] != 0) {
                        Dir = 2;
                        Pos[0]--;
                    }
                    else {
                        Pos[1]++;
                    }
                }
                else {
                    Dir = 2;
                    Pos[0]--;
                }
                break;
            case 2:
                if (Pos[0] > 0) {
                    if (Q[Pos[0] - 1, Pos[1]] != 0) {
                        Dir = 3;
                        Pos[1]--;
                    }
                    else {
                        Pos[0]--;
                    }
                }
                else {
                    Dir = 3;
                    Pos[1]--;
                }
                break;
            case 3:
                if (Q[Pos[0], Pos[1] - 1] != 0) {
                    Dir = 0;
                    Pos[0]++;
                }
                else {
                    Pos[1]--;
                }
                break;

        }
    }
}
0