結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-07-22 22:47:58 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 511 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 22,912 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 09:08:39 |
合計ジャッジ時間 | 1,093 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | scanf("%d", &n); | ~~~~~^~~~~~~~~~
ソースコード
#include <stdio.h>int n, f[30][30];int dx[4] = {1, 0, -1, 0};int dy[4] = {0, 1, 0, -1};int main() {scanf("%d", &n);int x = 0, y = 0, d = 0;for(int i = 1; i <= n * n; i++) {f[x][y] = i;int xx = x + dx[d];int yy = y + dy[d];if( ! (0 <= xx && xx < n && 0 <= yy && yy < n && f[xx][yy] == 0) ) { d++; d %= 4; }x += dx[d];y += dy[d];}for(int i = 0; i < n; i++) {for(int j = 0; j < n; j++) {printf("%s%03d", j == 0 ? "" : " ", f[j][i]);} printf("\n");}return 0;}