#include
#include
using namespace std;
typedef struct tagData {
char path[81];
int size = 0;
tagData* next[501];
}Node;
Node* root;
//Node mDB[10002];
int mDBcur = 0;
void strCpy(char* dest, char* str) {
int idx = 0;
while (str[idx]) {
dest[idx] = str[idx];
idx++;
}
dest[idx] = str[idx];
}
int strCmp(char* str1, char* str2) {
int idx = 0;
while (str1[idx] && str2[idx]) {
if (str1[idx] != str2[idx])
break;
idx++;
}
return str1[idx] - str2[idx];
}
int strLen(char* str) {
int idx = 0;
while (str[idx])
idx++;
return idx;
}
Node* createNode() {
Node* newNode = (Node*)malloc(sizeof(Node));
newNode->size = 0;
for (int i = 0; i
newNode->next[i] = NULL;
}
//free(n);
//Node* newNode = &mDB[mDBcur++];
return newNode;
}
Node *mergeNode[501];
void mergeSort(Node * cur, int left, int mid, int right) {
if (cur == NULL)
return;
int K = left;
int L = left;
int R = mid + 1;
while (L <= mid && R <= right) {
if (strCmp(cur->next[L]->path, cur->next[R]->path)
mergeNode[K++] = cur->next[L++];
}
else {
mergeNode[K++] = cur->next[R++];
}
}
for (int i = L; i <= mid; i++) {
mergeNode[K++] = cur->next[L++];
}
for (int i = R; i <= right; i++) {
mergeNode[K++] = cur->next[L++];
}
for (int i = left; i <= right; i++) {
cur->next[i] = mergeNode[i];
}
}
void merge(Node * cur, int left, int right) {
if (left
int mid = (left + right) / 2;
merge(cur, left, mid);
merge(cur, mid + 1, right);
mergeSort(cur, left, mid, right);
}
}
void printAll(Node * cur, int depth) {
if (cur == NULL)
return;
merge(cur, 0, cur->size - 1);
for (int i = 0; i size; i++) {
for (int j = 0; j
cout << " ";
}
cout <next[i]->path <
printAll(cur->next[i], depth + 1);
}
}
int main() {
int N;
cin >> N;
root = createNode();
root->size = 0;
//root->next[0] = createNode();
for (int i = 0; i
char input[81];
cin >> input;
int strSize = strLen(input);
Node* cur = root;
int idx = 0;
char inStr[81];
int inIdx = 0;
while (input[idx]) {
if (input[idx] == '\\' || idx == strSize - 1) {
if (idx == strSize - 1) {
inStr[inIdx++] = input[idx];
}
inStr[inIdx] = '\0';
//중복체크
int isDuplication = -1;
for (int i = 0; i size; i++) {
if (cur->next[i] == NULL)
break;
if (strCmp(inStr, cur->next[i]->path) == 0) {
isDuplication = i;
break;
}
}
//노드정리
if (isDuplication == -1) {
cur->next[cur->size] = createNode();
strCpy(cur->next[cur->size]->path, inStr);
cur->size++;
cur = cur->next[cur->size - 1];
}
else {
cur = cur->next[isDuplication];
}
inIdx = 0;
idx++;
continue;
}
inStr[inIdx++] = input[idx];
idx++;
}
}
printAll(root, 0);
return 0;
}
어디서 틀렸을까요.. ?