/*
//암호화
#include <stdio.h>
int cyp[262150];
int pow(int a) {
if(a==1) return 0;
return 1+pow(a/2);
}
void f(int s, int k) {
int sum=0;
for(int i=s; i<s+k; i++) {
sum+=cyp[i];
}
if(sum==0) {
printf("0");
}
else if(sum==k) {
printf("1");
}
else {
printf("-");
f(s, k/2);
f(s+k/2, k/2);
}
}
int main() {
int n;
scanf("%d", &n);
for(int i=0; i<n; i++)
scanf("%1d", &cyp[i]);
f(0, n); //[0, n)
}
input : 8 11010000
output : --1-010
*/
//복호화
#include <stdio.h>
int n, ptr;
char cyp[262150];
void f(int i, int l) { //index, length
char v=cyp[ptr++]; //ptr을 따로 지정하는 것이 관건!
if(v=='\0') {
return;
}
if(v=='-') {
f(i, l/2);
f(i+l/2, l/2);
}
else {
for(int j=0; j<l; j++)
printf("%c", v);
}
}
int main() {
scanf("%d %s", &n, cyp);
f(0, n); //[0, n)
}
To embed this project on your website, copy the following code and paste it into your website's HTML: