-
Notifications
You must be signed in to change notification settings - Fork 0
/
RLE.java
46 lines (39 loc) · 928 Bytes
/
RLE.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
import java.util.Scanner;
import java.util.regex.*;
class RLE {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
String src = sc.nextLine();
System.out.println(l(src));
}
static int l(String e){
int total = 0;
char[] o = e.toCharArray();
String right; String p = "\\d+";
Pattern pattern = Pattern.compile(p);
Matcher matcher;
for(int i=0; i<o.length; i++){
if(l(o[i])){
if(i==o.length-1){
total++;
}else{
if(!l(o[i+1])){
right = e.substring(i+1, e.length());
matcher = pattern.matcher(right);
if(matcher.find()){
total += Integer.parseInt(matcher.group());
}else{
total++;
}
}else{
total++;
}
}
}
}
return total;
}
static boolean l(char c){
return Character.isLetter(c);
}
}