SWEA1289 원재의 메모리 복구하기

·2022년 4월 18일
0

SWEA 알고리즘

목록 보기
2/29

문제를 읽고 이해할 수 있으면 구현은 어렵지 않다.

import java.util.Scanner;
import java.io.FileInputStream;


class Solution
{
	public static void main(String args[]) throws Exception
	{
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();

		for(int test_case = 1; test_case <= T; test_case++)
		{
			char[] c = sc.next().toCharArray();
			int count = 0;
			if(c[0] == 49
					) count++;
			for(int i = 0; i < c.length - 1; i++) {
				if(c[i] != c[i+1]) {
					count++;
				}
			}
			System.out.printf("#%d %d\n", test_case, count);
			
		}
	}
}
profile
SSAFY 7기

0개의 댓글