forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswe1289.java
More file actions
49 lines (36 loc) · 1.03 KB
/
swe1289.java
File metadata and controls
49 lines (36 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class swe1289 {
static Scanner sc = new Scanner(System.in);
static int answer = 0;
public static void main(String[] args) {
int t = sc.nextInt();
for (int T = 1; T <= t; T++) {
String input_Buffer = sc.next();
answer = solution(input_Buffer);
System.out.println("#" + T + " " + answer);
}
}
public static int solution(String input)
{
int count = 0;
char last_char = input.charAt(input.length()-1);
for(int i = input.length()-2; i>=0; i--)
{
if(input.charAt(i) == last_char)
continue;
else if(input.charAt(i) != last_char)
{
last_char = input.charAt(i);
count++;
}
}
//첫 숫자가 1이면 한번더 바꿔줘야하니 +1
if(input.charAt(0) == '1')
{
count++;
}
return count;
}
}