๋ฌธ์
์ฝ๋
#include <iostream>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int N,find; cin>>N>>find;
int arr[1000][1000] = {0, };
int x=0, y=0;
int num = N*N;
int down_up_cnt = N, right_left_cnt=N-1;
for(int i=0; i<N*N; i++){
switch(i%4){
case 0: //์๋๋ฐฉํฅ
if(arr[x][y]!=0) break;
for(int k=0; k<down_up_cnt; k++){
arr[x][y]=num;
num--;
x++;
}
x--;
y++;
down_up_cnt--;
break;
case 1: //์ค๋ฅธ์ชฝ ๋ฐฉํฅ
if(arr[x][y]!=0) break;
for(int k=0; k<right_left_cnt; k++){
arr[x][y]=num;
num--;
y++;
}
y--;
x--;
right_left_cnt--;
break;
case 2: //์์ชฝ ๋ฐฉํฅ
if(arr[x][y]!=0) break;
for(int k=0; k<down_up_cnt; k++){
arr[x][y]=num;
num--;
x--;
}
x++;
y--;
down_up_cnt--;
break;
case 3: //์ผ์ชฝ ๋ฐฉํฅ
if(arr[x][y]!=0) break;
for(int k=0; k<right_left_cnt; k++){
arr[x][y]=num;
num--;
y--;
}
y++;
x++;
right_left_cnt--;
break;
}
}
for(int i=0; i<N; i++){
for(int k=0; k<N; k++){
if(arr[i][k]==find) x=i+1, y = k+1;
cout<<arr[i][k]<<' ';
}
cout<<'\n';
}
cout<<x<< ' '<<y;
}
ํ์ด(10๋ถ)
๋ฌํฝ์ด ๋ฟ์ !
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 2504๋ฒ - ๊ดํธ์ ๊ฐ (0) | 2022.03.16 |
---|---|
[๋ฐฑ์ค,c++] 1748๋ฒ - ์ ์ด์ด ์ฐ๊ธฐ1 (0) | 2022.03.15 |
[๋ฐฑ์ค,c++] 1912๋ฒ - ์ฐ์ํฉ (0) | 2022.03.15 |
[๋ฐฑ์ค,c++] 1094๋ฒ - ๋ง๋๊ธฐ (0) | 2022.03.14 |
[๋ฐฑ์ค,c++] 1021๋ฒ - ํ์ ํ๋ ํ (0) | 2022.03.11 |
[๋ฐฑ์ค,c++] 2346๋ฒ - ํ์ ํฐ๋จ๋ฆฌ๊ธฐ (0) | 2022.03.11 |
๋๊ธ