結果

問題 No.401 数字の渦巻き
ユーザー mudbdbmudbdb
提出日時 2016-07-23 00:41:02
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 22,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 05:50:28
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 0 ms
5,376 KB
testcase_12 AC 0 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 0 ms
5,376 KB
testcase_17 AC 0 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
testcase_19 AC 0 ms
5,376 KB
testcase_20 AC 0 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 0 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 0 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 0 ms
5,376 KB
testcase_29 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:5:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |   scanf("%d",&N);
      |   ^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
int M[31][31];
int main() {
  int N;
  scanf("%d",&N);
  int i,j;
  for (i=0; i<=N; i++) {
    for (j=0; j<=N; j++) {
      M[i][j] = 0;
    }
  }
  int c = 1;
  i = 0;
  for (j=0; j<N; j++) {
    M[i][j] = c++;
  }
  j = N-1;
  for (i=1; i<N; i++) {
    M[i][j] = c++;
  }
  i = N-1;
  for (j=N-2; j>=0; j--) {
    M[i][j] = c++;
  }
  j = 0;
  for (i=N-2; i>=1; i--) {
    M[i][j] = c++;
  }
  if (N>=3) {
    int stpi[4] = { 0,1,0,-1 };
    int stpj[4] = { 1,0,-1,0 };
    int k = 0;
    int rtry = 0;
    i = 1;
    j = 1;
    while (1) {
      M[i][j] = c++;
      RTRY:
      i += stpi[k];
      j += stpj[k];
      if (M[i][j] != 0) {
        i -= stpi[k];
        j -= stpj[k];
        k++;
        k%=4;
        rtry++;
        if (rtry >= 3) {
          break;
        } else {
          goto RTRY;
        }
      }
      rtry = 0;
    }
  }
  for (i=0; i<N; i++) {
    for (j=0; j<N; j++) {
      printf("%03d",M[i][j]);
      if (j<N-1) {
        printf(" ");
      } else {
        printf("\n");
      }
    }
  }
  return 0;
}
0