[프로그래머스] 삼각 달팽이 - c++
규칙찾기
vector<int> solution(int n) {
vector<int> answer;
vector<vector<int>> tmp(n, vector<int>(n));
int value=1;
int type=0, x=0, y=0;
for(int i=0;i<n;i++){
switch(type)
{
case 0:
for(int j=i;j<n;j++){
tmp[x++][y]=value++;
}
x--;
y++;
type=1;
break;
case 1:
for(int j=i;j<n;j++){
tmp[x][y++]=value++;
}
x--;
y-=2;
type=2;
break;
case 2:
for(int j=i;j<n;j++){
tmp[x--][y--]=value++;
}
y++;
x+=2;
type=0;
break;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < i + 1; j++)
{
answer.push_back(tmp[i][j]);
}
}
return answer;
}
Author And Source
이 문제에 관하여([프로그래머스] 삼각 달팽이 - c++), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@mopevxw/프로그래머스-삼각-달팽이-c저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)