結果

問題 No.401 数字の渦巻き
ユーザー toto
提出日時 2025-03-25 15:58:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,001 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 28,544 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-25 15:58:48
合計ジャッジ時間 1,633 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%d",&val);
      |         ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(){
	int val = 0;
	scanf("%d",&val);
	
	// 出力する配列
	int ans[val][val];
	// 初期化
	for(int i = 0;i < val;i ++){
		for(int j = 0;j < val;j ++){
			ans[i][j] = 0;
		}
	}
	
	int reference = 0;
	int i = 1;
	while(i != (val * val) + 1){
		if(reference % 4 == 0){
			// みぎ
			for(int j = reference / 4;j < val - (reference / 4);j ++){
				ans[reference / 4][j] = i;
				i++;
			}
		}else if(reference % 4 == 1){
			// した
			for(int j = reference / 4;j < val - (reference / 4);j ++){
				ans[j][reference / 4] = i;
				i++;
			}
		}else if(reference % 4 == 2){
			// ひだり
			for(int j = val - (reference / 4);j < reference/ 4;j --){
				ans[reference / 4][j] = i;
				i++;
			}
		}else if(reference % 4 == 3){
			// うえ
			for(int j = val - (reference / 4);j < reference/ 4;j --){
				ans[j][reference / 4] = i;
				i++;
			}
		}
	}
	
	for(int i = 0;i < val;i ++){
		for(int j = 0;j < val;j ++){
			printf("%03d ",ans[i][j]);
		}
		printf("\n");
	}
}
0