結果

問題 No.401 数字の渦巻き
ユーザー ku_material_roku_material_ro
提出日時 2016-09-26 01:47:20
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,043 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 64,240 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-11-18 15:03:40
合計ジャッジ時間 18,383 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 WA * 18 RE * 6 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main(){
	string s;
	int map[30][30] = {0};
	string ans[30][30];
	int n; cin >> n;
	int vx[4] = { 1,0, -1, 0 };
	int vy[4] = { 0,1, 0, -1 };
	int x = 0;
	int y = 0;
	int i = 1;
	int d = 0;
	while (i<=n*n){
		//cout << d <<"d"<< endl;
		//cout << x << "x" << endl;
		//cout << y << endl;
		map[x][y] = i;
		//cout << x << "x" << endl;
		//cout << y << "y" << endl;
		//cout << map[x + vx[d]][y + vy[d]] << "map[x + vx[d]][y + vy[d]]" << endl;

		if (x+vx[d] == n || y+vy[d] == n  || map[x + vx[d]][y + vy[d]] != 0){
			d += 1;
			if (d == 4){
				d = 0;
			}
		}
		//cout << d << "d" << endl;
		x += vx[d];
		y += vy[d];
		i++;
		
	}
	for (int i = 0; i < n; i++){
		for (int i1 = 0; i1 < n-1; i1++){
			s = to_string(map[i1][i]);
			string s1((3 - s.length()), '0');
			ans[i1][i] = s1 + s;
			cout << ans[i1][i] << " ";
		}
		s = to_string(map[n-1][i]);
		string s1((3 - s.length()), '0');
		ans[n-1][i] = s1 + s;
		cout << ans[n - 1][i] << endl;
	}
	return 0;
}
0