翻硬币Java
跟前面比起来,显然是最轻松的一集
Java样例
import java.util.*;
public class Main {
static char[] op;
static char[] end;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
op = sc.nextLine().toCharArray();
end = sc.nextLine().toCharArray();
int n = op.length;
int step=0;
for(int i=0;i<n;i++) {
if(op[i]!=end[i]) {
step++;
turn(i,n);
}
}
System.out.println(step);
}
public static void turn(int i,int n) {
if(op[i]=='o') op[i]='*';
else op[i]='o';
if(i+1<n) {
if(op[i+1]=='o') op[i+1]='*';
else op[i+1]='o';
}
}
}