-
Notifications
You must be signed in to change notification settings - Fork 0
/
p145.java
52 lines (41 loc) · 1.32 KB
/
p145.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
package com.caiomed03.aceptaelreto;
import java.util.*;
public class p145 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
char[] tren;
Stack<Character> parejas;
int res;
while (s.hasNext()) {
tren = s.next().toCharArray();
parejas = new Stack<>();
res = 0;
for (int i = 0; i < tren.length; i++) {
switch (tren[i]) {
case '@':
parejas.clear();
break;
case 'H':
case 'h':
parejas.push(tren[i]);
break;
case 'M':
if (!parejas.isEmpty() && parejas.pop() == 'H') {
res++;
} else {
parejas.push(tren[i]);
}
break;
case 'm':
if (!parejas.isEmpty() && parejas.pop() == 'h') {
res++;
} else {
parejas.push(tren[i]);
}
break;
}
}
System.out.println(res);
}
}
}