結果

問題 No.401 数字の渦巻き
ユーザー toto
提出日時 2025-03-25 16:33:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,138 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 28,928 KB
実行使用メモリ 14,768 KB
最終ジャッジ日時 2025-03-25 16:33:12
合計ジャッジ時間 4,427 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 2 RE * 2 TLE * 1 -- * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
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];
	
	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 ++){
				printf("右i:%d j:%d\n",reference / 4,j);
				ans[reference / 4][j] = i;
				i++;
			}
		}else if(reference % 4 == 1){
			// した
			for(int j = (reference / 4) + 1;j < val - (reference / 4) + 1;j ++){
				printf("下i:%d j:%d\n",j,(reference / 4) + 1);
				ans[j][(reference / 4) + 1] = i;
				i++;
			}
		}else if(reference % 4 == 2){
			// ひだり
			for(int j = val - (reference / 4);j > reference/ 4;j --){
				printf("左i:%d j:%d\n",reference / 4,j);
				ans[reference / 4][j] = i;
				i++;
			}
		}else if(reference % 4 == 3){
			// うえ
			for(int j = val - (reference / 4);j > reference/ 4;j --){
				printf("上i:%d j:%d\n",j,reference / 4);
				ans[j][reference / 4] = i;
				i++;
			}
		}
		reference++;
	}
	
	for(int i = 0;i < val;i ++){
		for(int j = 0;j < val;j ++){
			printf("%03d ",ans[i][j]);
		}
		printf("\n");
	}
}
0