// The below commented functions are for your reference. If you want
// to use it, uncomment these functions.
/
int mstrcmp(const char a, const char *b)
{
int i;
for (i = 0; a[i] != '\0'; i++)
{
if (a[i] != b[i])
return a[i] - b[i];
}
return a[i] - b[i];
}
int mstrlen(const char *a)
{
int len = 0;
while (a[len] != '\0')
len++;
return len;
}
void mstrncpy(char dest, const char src, int len)
{
for (int i = 0; i<len; i++)
{
dest[i] = src[i];
}
dest[len] = '\0';
}
*/
void mstrcpy(char dest, const char src)
{
int i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = src[i];
}
int mstrncmp(const char a, const char b, int l, int r)
{
int j = 0;
for (int i = l+1; i < r; i++,j++){
if (a[i] != b[j])
return a[i] - b[j];
}
if (b[j])
return 1;
return 0;
}
int parse(const char path, int p) {
int l = 0, c = 0;
while (path[l] != '\0') {
if (path[l] == '/')
p[c++] = l;
l++;
}
return c;
}
Node goDown(char path) {
Node *now = Root;
int pos[700];
int cnt = parse(path, pos);
int i = 1, before = 0;
while(i<cnt){
if (i != before) {
now = now->child;
before = i;
}
if(mstrncmp(path, now->key, pos[i - 1], pos[i]) == 0) // 같을경우
i++;
else
now = now->next;
}
return now;
include
using namespace std;
define NAME_MAXLEN 6
define PATH_MAXLEN 1999
define MAX_DIRECTORY 50005
// The below commented functions are for your reference. If you want // to use it, uncomment these functions. / int mstrcmp(const char a, const char *b) { int i; for (i = 0; a[i] != '\0'; i++) { if (a[i] != b[i]) return a[i] - b[i]; } return a[i] - b[i]; }
int mstrlen(const char *a) { int len = 0;
}
void mstrncpy(char dest, const char src, int len) { for (int i = 0; i<len; i++) { dest[i] = src[i]; } dest[len] = '\0'; } */
void mstrcpy(char dest, const char src) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = src[i]; }
int mstrncmp(const char a, const char b, int l, int r) { int j = 0; for (int i = l+1; i < r; i++,j++){ if (a[i] != b[j]) return a[i] - b[j]; } if (b[j]) return 1; return 0; }
struct Node { Node parent, child, prev, next; char key[NAME_MAXLEN+1]; bool terminal;
};
Node Root; int Dsize; Node node[MAX_DIRECTORY2];
Node* alloc() { return &node[Dsize++]; }
void init(int n) { Dsize = 0; Root = alloc(); Root->init((char *)"/"); }
int parse(const char path, int p) { int l = 0, c = 0; while (path[l] != '\0') { if (path[l] == '/') p[c++] = l; l++; } return c; }
Node goDown(char path) { Node *now = Root; int pos[700]; int cnt = parse(path, pos);
}
void traverse(Node src, Node nuw) { if (src->child) { Node tmp = alloc(); tmp->init(src->child->key); nuw->terminal = false; nuw->child = tmp; tmp->parent = nuw; traverse(src->child, tmp); } if (src->next) { Node tmp = alloc(); tmp->init(src->next->key); nuw->next = tmp; tmp->prev = nuw; traverse(src->next, tmp); } }
void cmd_mkdir(char path[PATH_MAXLEN + 1], char name[NAME_MAXLEN + 1]) { Node now = goDown(path); Node nuw = alloc(); nuw->init(name);
}
void cmd_rm(char path[PATH_MAXLEN + 1]) { Node src = goDown(path); //기존 연결 끊기 if (src->prev == 0 && src->next == 0) { src->parent->terminal = true; src->parent->child = 0; } else if (src->prev != 0 && src->next != 0) { Node N = src->next; N->prev = src->prev; src->prev->next = N; src->next = src->prev = 0; } else if (src->prev == 0) { Node *N = src->next; src->parent->child = N; N->parent = src->parent; N->prev = src->next = 0; } else if (src->next == 0) { src->prev->next = 0; src->prev = 0; } }
void cmd_cp(char srcPath[PATH_MAXLEN + 1], char dstPath[PATH_MAXLEN + 1]) { Node src = goDown(srcPath); Node dst = goDown(dstPath);
}
void cmd_mv(char srcPath[PATH_MAXLEN + 1], char dstPath[PATH_MAXLEN + 1]) { Node src = goDown(srcPath); //기존 연결 끊기 if (src->prev == 0 && src->next == 0) { src->parent->terminal = true; src->parent->child = 0; } else if (src->prev != 0 && src->next != 0) { Node N = src->next; N->prev = src->prev; src->prev->next = N; src->next = src->prev = 0; } else if (src->prev == 0) { Node *N = src->next; src->parent->child = N; N->parent = src->parent; N->prev = src->next = 0; } else if (src->next == 0) { src->prev->next = 0; src->prev = 0; }
}
void countNode(Node *src,int &cnt) { if (src->child) { cnt++; countNode(src->child, cnt); } if (src->next) { cnt++; countNode(src->next, cnt); } }
int cmd_find(char path[PATH_MAXLEN + 1]) { Node *src = goDown(path); int cnt = 0; if(src->child != 0) countNode(src->child, ++cnt); //cout << cnt << endl; return cnt; }
void test() { cout << "hi" << endl; init(5);
}