解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
private static int max=0;
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
char chs[]=input.next().toCharArray();
for (int cut = 1; cut<chs.length; cut++) {
int mun=0,k=3;
for (int i = cut;; i++) {
if(i==chs.length)i=0;
if(chs[i]=='w'){
mun++;
}
if(chs[i]=='r'&&(k==3||k==0)){
mun++;
k=0;
}
if(chs[i]=='b'&&(k==3||k==1)){
mun++;
k=1;
}
if(chs[i]=='b'&&k!=3&&k!=1)break;
if(chs[i]=='r'&&k!=3&&k!=0)break;
}
k=3;
for (int i = cut-1;; i--) {
if(i==-1)i=chs.length-1;
if(chs[i]=='w'){
mun++;
}
if(chs[i]=='r'&&(k==3||k==0)){
mun++;
k=0;
}
if(chs[i]=='b'&&(k==3||k==1)){
mun++;
k=1;
}
if(chs[i]=='b'&&k!=3&&k!=1)break;
if(chs[i]=='r'&&k!=3&&k!=0)break;
}
if(mun>max)max=mun;
}
System.out.println(max);
}
}
0.0分
0 人评分