結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-09-26 01:55:44 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,088 bytes |
コンパイル時間 | 584 ms |
コンパイル使用メモリ | 65,028 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 15:04:24 |
合計ジャッジ時間 | 1,451 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <iostream> #include <string> #include <math.h> using namespace std; int main(){ string s; int map[100][100] = {0}; string ans[100][100]; 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 || x + vx[d] == -1 || y + vy[d] == -1 || 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; }