水题一道,对于两种形式 10101和01010,只用计算出一种情况,N-result就是另一种情况的switch次数
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt())
{
int n = sc.nextInt();
int oneFirst = 0;
boolean one = true;
for (int i = 0; i < n; i++)
{
int number = sc.nextInt();
if (one)
{
if (number == 0)
oneFirst++;
}
else
{
if (number == 1)
oneFirst++;
}
one = !one;
}
System.out.println(oneFirst < n - oneFirst ? oneFirst : n
- oneFirst);
}
}
}