Taene's
[분할정복] 백준-칸토어 집합 C++ 4779번 본문
https://www.acmicpc.net/problem/4779
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void change(int num, int index, string& dash)
{
if (num == 1)
{
return;
}
num /= 3;
string k(num, ' ');
dash.replace(num + index, num, k);
change(num, index, dash);
change(num, index + 2 * num, dash);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
while (cin >> N)
{
if (N == 0)
{
cout << '-' << '\n';
}
else
{
int c = pow(3, N);
string dash(c, '-');
change(dash.size(), 0, dash);
cout << dash << endl;
}
}
return 0;
}
// while(!cin.eof())는 안됐다. while(cin>>N)
'알고리즘 문제풀이 > 분할정복' 카테고리의 다른 글
[분할정복] 백준-치킨 TOP N C++ 11582번 (0) | 2025.02.06 |
---|