P8597 [蓝桥杯 2013 省 B] 翻硬币
AC

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.nextLine();
		String s2 = sc.nextLine();
		char[] c1 = s1.toCharArray();
		char[] c2 = s2.toCharArray();
		int t = c1.length - 1;
		int sum = 0;
		for(int i=0;i<t;i++) {
			if(c1[i]!=c2[i]) {
				if(c1[i] == '*') {
					c1[i] = 'o';
					if(c1[i+1] == '*') {
						c1[i+1] = 'o';
					}else {
						c1[i+1] = '*';						
					}
					sum++;
				}else {
					c1[i] = '*';
					if(c1[i+1] == '*') {
						c1[i+1] = 'o';
					}else {
						c1[i+1] = '*';						
					}
					sum++;
				}
			}
		}
		System.out.println(sum);
	}
}
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐