結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-11-20 01:41:24 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 888 bytes |
コンパイル時間 | 121 ms |
コンパイル使用メモリ | 22,144 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-27 06:33:20 |
合計ジャッジ時間 | 1,180 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:5:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 5 | scanf("%d", &n); | ^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>int main() {int n;scanf("%d", &n);int map[30][30] = {};enum status { Right, Down, Left, Up } state = Right;int x = 0, y = 0;int i, j;for (i = 1; i <= n * n; i++) {map[x][y] = i;if (i == n * n) break;switch (state) {case Right:if (x + 1 >= n || map[x + 1][y] > 0) {state = Down;i--;}else x++;break;case Down:if (y + 1 >= n || map[x][y + 1] > 0) {state = Left;i--;}else y++;break;case Left:if (x - 1 < 0 || map[x - 1][y] > 0) {state = Up;i--;}else x--;break;case Up:if (y - 1 < 0 || map[x][y - 1] > 0) {state = Right;i--;}else y--;break;}}for (i = 0; i < n; i++) {for (j = 0; j < n; j++) {printf("%03d", map[j][i]);if (j < n - 1) printf(" ");}printf("\n");}return 0;}