SSONG Cloud
[SWEA] 1289 원재의 메모리 복구하기 본문
반응형
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=Integer.parseInt(sc.nextLine());
for(int test_case = 1; test_case <= T; test_case++)
{
String code = sc.nextLine();
String[] str = code.split("");
int[] arr = new int[str.length];
boolean flag = false;
int sum = 0;
for (int i = 0; i < code.length(); i++) {
arr[i] = Integer.parseInt(str[i]);
}
for (int j = 0; j < arr.length; j++) {
if(flag) {
if(arr[j-1] != arr[j]) sum++;
continue;
}
if (arr[j] == 1) {
flag = true;
sum++;
continue;
}
}
System.out.println("#"+(test_case)+" "+sum);
}
}
}
반응형
'Algorithm > SW Expert Academy' 카테고리의 다른 글
[SWEA] 2005 파스칼의 삼각형 (0) | 2021.01.24 |
---|---|
[SWEA] 1974 수도쿠 검증 (0) | 2021.01.24 |
[SWEA] 1284 수도 요금 경쟁 (0) | 2021.01.24 |
[SWEA] 간단한 369게임 (0) | 2021.01.24 |
[SWEA] 1204 최빈수 구하기 (0) | 2021.01.24 |
Comments