-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP002C.java
More file actions
31 lines (26 loc) · 1001 Bytes
/
P002C.java
File metadata and controls
31 lines (26 loc) · 1001 Bytes
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
//Shejia Zhu
//2018-06-04
//To be modified
import java.util.*;
public class P002C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String input = sc.next();
String[] shortcut = {"AA","BB","XX","YY","AB","BA","AX","XA","AY","YA","BX","XB","BY","YB","XY","YX"};
int buttons = 100000000;
String copy_input = input;
for (int i=0; i<shortcut.length; i++) {
for (int j=i+1; j<shortcut.length; j++) {
if (i!=j && copy_input.contains(shortcut[i]) && copy_input.contains(shortcut[j])) {
copy_input = copy_input.replace(shortcut[i], "L");
copy_input = copy_input.replace(shortcut[j], "R");
if (copy_input.length()<buttons)
buttons = copy_input.length();
copy_input = input;
}
}
}
System.out.println(buttons);
}
}