Algorithm/SWEA

[D3] 원재의 메모리 복구하기

징주 2021. 8. 4. 23:06

https://swexpertacademy.com/main/talk/solvingClub/problemPassedUser.do

 

SW Expert Academy

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

swexpertacademy.com

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Solution {
 
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
         
        for(int i=0;i<t;i++) {
            char [] bit = br.readLine().toCharArray();
            char tmp = ' ';
            int count = 1;
            tmp = bit[bit.length-1];
            for(int j=bit.length-2;j>=0;j--) {
                if(tmp != bit[j]) {
                    count++;
                    tmp = bit[j];
                }
                if(j==0 && bit[j]=='0') count--;
                 
            }
            System.out.println("#"+(i+1)+" "+count);
        }
         
    }
 
}
//뒤에서부터 0,1중 고르고 반복하고 또 바뀌면 카운트 오름 
//계속 반복
//젤앞이 0이면 끝
 
/*
2
0011        
100         
 
-> 1
-> 2
 */