#include <string> #include <vector> #include <iostream> using namespace std; vector<int> solution(int n) { vector<int> answer; string paper = "0"; for(int i = 1; i < n; i++) { string temp_paper = paper; // 원래 종이의 가운데 부분만 다른 숫자로 변경 if(temp_paper[temp_paper.size()/2] == '0') { temp_paper[temp_paper.size()/2] = '1'; } else { temp_paper[temp_paper.size()/2] = '0'; } // 0 더하고, 가운데 부분만 변경한 종이를 이어붙이면 되는 규칙 paper += "0"; paper += temp_paper; } for(int i = 0; i < paper.size(); i++) { answer.push_back(paper[i]-'0'); } return answer; } | cs |
'Programmers > Level 3' 카테고리의 다른 글
[프로그래머스 3] 보행자 천국 (C/C++) (0) | 2020.03.07 |
---|---|
[프로그래머스 3] 가장 긴 팰린드롬 (C/C++) (★★) (0) | 2020.03.07 |
[프로그래머스 3] 2xN 타일링 (C/C++) (0) | 2020.03.06 |
[프로그래머스 3] 길찾기 게임 (C/C++) (★★) (0) | 2020.03.05 |
[프로그래머스 3] 매칭 점수 (C/C++) (0) | 2020.03.01 |