Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created May 24, 2019 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/8d177011a49b269f406a03f1b01160d5 to your computer and use it in GitHub Desktop.
Save fpdjsns/8d177011a49b269f406a03f1b01160d5 to your computer and use it in GitHub Desktop.
[algospot][분할정복] 쿼드 트리 뒤집기 : https://www.algospot.com/judge/problem/read/QUADTREE
#include<iostream>
#include<string>
#include<vector>
using namespace std;
/*
* 시간복잡도 : O(N)
* 공간복잡도 : O(N)
*/
string solve(string::iterator& it) {
char head = *it;
it++;
if (head == 'w' || head == 'b') {
return string(1, head); // char to string
}
vector<string> arr(4);
for (int i = 0; i < 4; i++) {
arr[i] = solve(it);
}
// if head not 'w' or 'b' -> must 'x'.
return 'x' + arr[2] + arr[3] + arr[0] + arr[1];
}
int main() {
int N;
cin >> N;
while (N--) {
string input;
cin >> input;
string::iterator it = input.begin();
cout << solve(it) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment