Niu Niu likes colorful things, especially colorful tiles. Niu Niu's room is lined with L square tiles. There are four possible colors for each brick: red, green, blue, and yellow. Given a string S, if the i-th character of S is 'R', 'G', 'B' or 'Y', the colors of the i-th tiles are red, green, blue or yellow, respectively.
Niu Niu decided to change the colors of some tiles, so that the colors of the two adjacent tiles are different. Please help Niu Niu calculate the minimum number of tiles he needs to replace.
Enter a description:
The input includes a line, a string S, the length of the string (1 ≤ length ≤ 10), and each string in the string is 'R', 'G', 'B' or 'Y'.
Output description:
Output an integer to indicate the minimum number of tiles that Niu Niu needs to replace
Example 1
enter
RRRRRR
Output
3
import java.util.Scanner;public class replaceColor { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str=sc.nextLine(); getNum(str); } private static void getNum(String str) { // TODO Auto-generated method stub char[] ch=str.toCharArray(); int tem=0; int len=ch.length; if(len>=2){ for(int i=1;i<len-1;i=i+2){ if(ch[i]==ch[i-1] || ch[i]==ch[i+1]){ tem++; } } if(ch[len-1]==ch[len-2] && len%2==0){ tem++; } for(int i=2;i<len-2;i=i+2){ if(ch[i]==ch[i-1] && ch[i]==ch[i+1] && ch[i+1]!=ch[i+2] && ch[i-1]!=ch[i-2]){ tem--; } } System.out.println(tem); }}