import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int n;
String arr;
int i, j;
n = scan.nextInt();
arr= scan.next();
int red = 0, blue = 0;
int rs = 0, bs = 0;
int re=0,be=0;
for (i = 0; i < n; i++) {
if (arr.charAt(i) == 'R') {
red++;
}
else {
blue++;
}
}
for (i = 0; i < n; i++) {
if (i == 0 && arr.charAt(i)== 'R') {
rs = 1;
}
else if (i == 0 && arr.charAt(i) == 'B') {
bs = 1;
}
else {
if (arr.charAt(i - 1) != arr.charAt(i)) {
break;
}
if (arr.charAt(i) == 'R') {
rs++;
}
else {
bs++;
}
}
}
for (i = n-1; i >= 0; i--) {
if (arr.charAt(i) == 'R' && i == n - 1) {
re = 1;
}
else if (arr.charAt(i) == 'B' && i == n - 1) {
be = 1;
}
else {
if (arr.charAt(i + 1) != arr.charAt(i)) {
break;
}
if (arr.charAt(i) == 'R') {
re++;
}
else {
be++;
}
}
}
int val = red - rs;
val = Math.min(val, red - re);
val = Math.min(val, blue - bs);
val = Math.min(val, blue - be);
System.out.printf("%d", val);
}
}
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2749&sca=2060
'정올문제소스코드' 카테고리의 다른 글
1102 : 스택 (stack) (0) | 2021.10.31 |
---|---|
1761 : 숫자 야구 (0) | 2021.10.29 |
2259 : 참외밭 (0) | 2021.10.29 |
1836 : 연속부분합 찾기 (0) | 2021.10.29 |
1761 : 숫자 야구 (0) | 2021.10.29 |