알고리즘/문제풀이

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

BSHwan 2020. 1. 25. 01:38
반응형
import java.util.Scanner;

public class Solution {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int T = sc.nextInt();
		
		for(int testCase=1; testCase<=T; testCase++) {
			String st = sc.next();
			int count = 0;
			
			for(int i=0; i<st.length(); i++) {
				if(i==0) {
					if(st.charAt(i) == '1') count++;
				} else {
					if(st.charAt(i) != st.charAt(i-1)) count++;
				}
			}
			
			System.out.println("#" + testCase + " " + count);
			
		}
	}
}
반응형