Problem description
Xiao Ming is playing a "coin-flipping" game.
There are a number of coins lined up on the table. We use * to denote the positive side, and O for the opposite side (lowercase letters, not 0).
For example, the possible scenario is: **oo***oooo
If you flip the two coins on the left at the same time, change to: oooo***oooo
Now Xiao Ming's question is: if you know the initial state and to achieve the target State, can only flip the adjacent two coins at a time, then the specific situation, at least how many times to flip.
We agreed: Turn the next two coins called one-step operation, then ask:
Input format
Two lines of equal length string representing the initial state and the target state to be reached. Length of each line <1000
Output format
An integer that represents the minimum number of operation steps.
Sample Input 1
**********
o****o****
Sample Output 1
5
Sample Input 2
*o**o***o***
*o***o**o***
Sample Output 2
1
Import Java.util.Scanner;
public class Fanyingbi {public
static void Main (string[] args) {
int count = 0;
Scanner sc = new Scanner (system.in);
StringBuffer str1 = new StringBuffer (Sc.nextline ());
StringBuffer str2 = new StringBuffer (Sc.nextline ());
for (int i = 0; i < str1.length ()-1; i++) {
if (Str1.charat (i)! = Str2.charat (i)) {
Str2.setcharat (i, str1.ch Arat (i));
if (Str2.charat (i + 1) = = ' * ') {
Str2.setcharat ((i + 1), ' O '),
} else {
Str2.setcharat ((i + 1), ' * ');
}
++count;
}
}
System.out.println (count);
}
}