結果

問題 No.401 数字の渦巻き
ユーザー ku_material_roku_material_ro
提出日時 2016-09-26 01:43:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,043 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 63,708 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-29 11:25:08
合計ジャッジ時間 6,743 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 WA -
testcase_18 TLE -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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