-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lz78.java
55 lines (44 loc) · 1.56 KB
/
Lz78.java
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
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashMap;
import javafx.util.Pair;
/////////////////////////////////////////////////composition
public class Lz78 {
public static void main(String[] args) {
Scanner In = new Scanner(System.in);
String str = In.nextLine();
//System.out.println(str);
In.close();
ArrayList<String> tbl = new ArrayList<String>(1);
tbl.add("");
//HashMap<Integer,Character> tags = new HashMap();
ArrayList<Pair<Integer,Character>> tags = new ArrayList<Pair<Integer,Character>>(1);
int strlen = str.length();
int i=0;
String temp = "";
int tempnumber=0;
while(i<strlen) {
temp+=str.charAt(i);
if(tbl.contains(temp)){
i++;
tempnumber = tbl.indexOf(temp);
if(i==strlen) {
//tags.add(tempnumber, str.charAt(i-1));
Pair<Integer,Character> pairtemp = new Pair<Integer,Character>(tempnumber,' ');
tags.add(pairtemp);
break;
}
continue;
}
Pair<Integer,Character> pairtemp = new Pair<Integer,Character>(tempnumber, str.charAt(i));
tags.add(pairtemp);
tbl.add(temp);
temp = "";
i++;
}
for (Pair<Integer,Character> p: tags){
System.out.println(p.getKey() + " " + p.getValue());
}
/////////////////////////////////////////////////composition
}
}