티스토리 뷰

728x90

문제

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV19AcoKI9sCFAZN&categoryId=AV19AcoKI9sCFAZN&categoryType=CODE 

 

SW Expert Academy

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

swexpertacademy.com

 

풀이 및 소스코드

import java.io.*;

public class Solution {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<n;i++) {
			char[] bit = br.readLine().toCharArray();
			int len = bit.length;
			char nowbit = '0';
			int ans = 0;
			
			for(int j=0;j<len;j++) {
				if(nowbit != bit[j]) {
					nowbit = bit[j];
					ans++;
				}
			}
			sb.append("#"+(i+1)+" "+ans+"\n");
		}
		System.out.println(sb);
	}

}

 

반응형