-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest2004_6.java
More file actions
82 lines (65 loc) · 1.6 KB
/
Test2004_6.java
File metadata and controls
82 lines (65 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package org.line;
import java.util.ArrayList;
import java.util.List;
// 디렉토리...망.......;;;
public class Test2004_6 {
public static void main(String[] args) {
String[] d = { "/", "/hello", "/hello/tmp", "/root", "/root/abcd", "/root/abcd/etc", "/root/abcd/hello" };
String[] c = { "mkdir /root/tmp", "cp /hello /root/tmp", "rm /hello" };
solution(d, c);
}
static List<dir> list = new ArrayList<>();
public static String[] solution(String[] directory, String[] command) {
String[] answer = {};
//dir first = new dir("/");
for (int i = 0; i < directory.length; i++) {
String[] dirs = directory[i].split("/");
for (int j = 0; j < dirs.length; j++)
System.out.println(dirs[j] + " ");
String nd = dirs[0];
int idx = finddir(nd);
if(idx != -1){
list.get(idx).addChild(nd);
}
else {
list.add(new dir(nd));
idx = list.size()-1;
}
list.get(idx).addChild(dirs);
}
return answer;
}
static int finddir(String n) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).name.equals(n)) {
return i;
}
}
return -1;
}
}
class dir {
String name;
List<dir> child;
dir(String name) {
this.name = name;
this.child = new ArrayList<>();
}
void addChild(String[] dirs) {
for(int i=1; i<dirs.length; i++) {
int idx = find(dirs[i]);ss
if (idx != -1) {
child.add(new dir(n));
}
else
}
}
int find(String n) {
for (int i = 0; i < child.size(); i++) {
if (child.get(i).equals(n)) {
return i;
}
}
return -1;
}
}