글
[LuckyAlgorithm]Alternating Characters (20/77)
Algorithm
2017. 12. 13. 10:47
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int alternatingCharacters(String s){
int count = 0;
char save = ' ';
char[] c_arr = s.toCharArray();
for(int i=1;i<c_arr.length;i++) {
if(c_arr[i-1]==c_arr[i]){
count++;
}
}
return count;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
for(int a0 = 0; a0 < q; a0++){
String s = in.next();
int result = alternatingCharacters(s);
System.out.println(result);
}
}
}
'Algorithm' 카테고리의 다른 글
[LuckyAlgorithm]Day 26: Nested Logic(22/77) (0) | 2017.12.16 |
---|---|
[LuckyAlgorithm]Intro to Tutorial Challenges (21/77) (0) | 2017.12.14 |
[LuckyAlgorithm]Correctness and the Loop Invariant(19/77) (0) | 2017.11.29 |
[LuckyAlgorithm]Ice Cream Parlor(18/77) (0) | 2017.11.29 |
[LuckyAlgorithm]Divisible Sum Pairs (17/77) (0) | 2017.10.23 |