-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathencode.java
28 lines (25 loc) · 867 Bytes
/
encode.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
import java.util.*;
class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n_s = sc.nextInt();
int len_en_coding_s = sc.nextInt();
HashMap<String, Character> codewords = new HashMap<String, Character>();
for(int i = 0; i < n_s; i++){
char chr_s = sc.next().charAt(0);
String codeword = sc.next();
codewords.put(codeword, chr_s);
}
String encoded = sc.next();
String unencoded = new String();
String word = new String();
for(int i = 0; i < encoded.length(); i++){
word += encoded.charAt(i);
if(codewords.containsKey(word)){
unencoded += codewords.get(word);
word = new String();
}
}
System.out.println(unencoded);
}
}