結果

問題 No.401 数字の渦巻き
ユーザー LogicR_pimanLogicR_piman
提出日時 2016-09-26 04:08:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,638 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 57,896 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-11 21:10:58
合計ジャッジ時間 1,918 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>

using namespace std;

int main() {
	int n, nn, i, j, k, x = 0, y = 0, d = 0, e = 0, f = 0;
	string s, ii;

	cin >> n;
	nn = n*n;

	for (i = 0; i < n-1; i++) {
		for (j = 0; j < n * 4; j++) {
			s.insert(0, "0");
		}
		s.insert(0, "\n");
	}
	for (j = 0; j < n * 4; j++) {
		s.insert(0, "0");
	}
	//0と改行で構成された文字列S

	for (i = 1; i <= n; i++) {
		if (i == 1) x = 0;
		else x += 1;
		if (i < 10) d = 2;
		else if (i < 100) d = 3;
		else d = 4;
		e = y * (n * 4 + 1) + x * 4 - d + 4;
		ii = to_string(i) + " ";
		s.replace(e, d, ii);
	}
	//1行目は例外
	while(1){
		if (i > n) {
			for (k = 0; k < n - 1 - f; k++) {
				y += 1;
				if (i < 10) d = 2;
				else if (i < 100) d = 3;
				else d = 4;
				e = y * (n * 4 + 1) + x * 4 - d + 4;
				ii = to_string(i) + " ";
				s.replace(e, d, ii);
				i++;
			}
			for (k = 0; k < n - 1 - f; k++) {
				x -= 1;
				if (i < 10) d = 2;
				else if (i < 100) d = 3;
				else d = 4;
				e = y * (n * 4 + 1) + x * 4 - d + 4;
				ii = to_string(i) + " ";
				s.replace(e, d, ii);
				i++;
			}
			if (i > nn) break;
			for (k = 0; k < n - 2 - f; k++) {
				y -= 1;
				if (i < 10) d = 2;
				else if (i < 100) d = 3;
				else d = 4;
				e = y * (n * 4 + 1) + x * 4 - d + 4;
				ii = to_string(i) + " ";
				s.replace(e, d, ii);
				i++;
			}
			for (k = 0; k < n - 2 - f; k++) {
				x += 1;
				if (i < 10) d = 2;
				else if (i < 100) d = 3;
				else d = 4;
				e = y * (n * 4 + 1) + x * 4 - d + 4;
				ii = to_string(i) + " ";
				s.replace(e, d, ii);
				i++;
			}
			if (i > nn) break;
			f += 2;
		}
	}
	cout << s << endl;
	return 0;
}
0