結果

問題 No.401 数字の渦巻き
ユーザー mizzsig
提出日時 2016-07-22 22:38:54
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 54,836 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-06 09:05:52
合計ジャッジ時間 1,539 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <string>
#include <iostream>
using namespace std;
int main() {
int dxIn[] = {1, 0, -1, 0};
int dyIn[] = {0, 1, 0, -1};
int field[30][30];
for(int i = 0; i < 30; i++){
for(int j = 0; j < 30; j++){
field[i][j] = 0;
}
}
int n;
cin >> n;
int x=0, y=0;
int dInd = 0;
int num=1;
while(num <= n * n){
field[x][y] = num;
if((x+dxIn[dInd] == n) || (y+dyIn[dInd] == n) || (x+dxIn[dInd]==-1) || (y+dyIn[dInd]==-1)){
dInd = (dInd + 1) % 4;
}else if(field[x+dxIn[dInd]][y+dyIn[dInd]] > 0){
dInd = (dInd + 1) % 4;
}
x+=dxIn[dInd]; y+=dyIn[dInd];
num++;
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(field[j][i] < 10){
cout << "00";
}else if(field[j][i] < 100){
cout << "0";
}
cout << field[j][i] << " ";
}
cout << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0