
package test;
import java.io.IOException;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
for (int k = 0; k < test; k++) {
int count=0;
String v = sc.next();
int size=v.length();
int[] array = new int[size];
int[] temp = new int[size];
for(int i=0; i<size; i++) {
array[i]=Integer.parseInt(v.substring(i, i+1));
}
for(int i=0; i<size; i++) {
temp[i]=0;
}
for(int i=0; i<size; i++) {
if(array[i]==temp[i]) {
}else if(temp[i]==0){
for(int j=i; j<size; j++) {
temp[j]=1;
}
count++;
}else if(temp[i]==1){
for(int j=i; j<size; j++) {
temp[j]=0;
}
count++;
}
}
System.out.println("#"+(k+1)+" "+count);
}
}
}
1. 문자열을 받아 배열에 넣어준다.
2. 변경이 될 배열에 0000을 넣어준다
3. 기준의 배열과 값이 같으면 넘기고 아니면 비교배열의 수를 반전시키면서 count++
'알고리즘(종합) > Lv.3' 카테고리의 다른 글
1225 - 암호생성기 (0) | 2022.11.18 |
---|---|
1209 - sum (0) | 2022.11.18 |
1208 - Flatten (0) | 2022.11.17 |
1244. 최대 상금 (0) | 2022.11.16 |
1206 - View 조망권 (0) | 2022.11.14 |