티스토리 뷰
1289. 원재의 메모리 복구하기
import java.util.Scanner;
public class Solution_D3_1289_원재의메모리복구하기 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 1; tc <= T; tc++) {
char[] arr = sc.next().toCharArray();
int state = arr[0] - '0';
int cnt = (state == 1 ? 1 : 0);
for (int i = 1; i < arr.length; i++) {
int n = arr[i] - '0';
if (state != n) {
cnt++;
state = n;
}
}
System.out.println("#" + tc + " " + cnt);
}
}
}
'코딩테스트 > SW Expert' 카테고리의 다른 글
[SWEA] 1210. [S/W 문제해결 기본] 2일차 - Ladder1 (0) | 2021.02.04 |
---|---|
[SWEA] 1983. 조교의 성적 매기기 (0) | 2021.02.01 |
[SWEA] 1984. 중간 평균값 구하기 (0) | 2021.01.31 |
[SWEA] 1986. 지그재그 숫자 (0) | 2021.01.31 |
[SWEA] 2005. 파스칼의 삼각형 (0) | 2021.01.30 |
댓글