티스토리 뷰

1289. 원재의 메모리 복구하기

swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV19AcoKI9sCFAZN&categoryId=AV19AcoKI9sCFAZN&categoryType=CODE&problemTitle=%EB%A9%94%EB%AA%A8%EB%A6%AC&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

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);
		}

	}

}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
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
글 보관함