BOJ 1439 뒤집기
-
변수
String S; //주어지는 문자열 int cnt; //바뀌는 횟수
-
로직
- 한칸씩 확인하면서 0->1로 1->0으로 바뀌는 횟수 카운트
-
코드
package com.ssafy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BOJ_1439_뒤집기_210105 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String S = br.readLine();
int cnt = 0;
char now = S.charAt(0);
for (int i = 1; i < S.length(); i++) {
if(now != S.charAt(i)) {
cnt++;
now = S.charAt(i);
}
}
System.out.println((cnt+1)/2);
}
}
Leave a comment