import java.util.Scanner; /** * 7 * 1111000 * 0010011 */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String nStr = in.next(); int n = Integer.parseInt(nStr); String A = in.next(); String B = in.next(); int res = solution(n, A, B); System.out.println(res); } } private static int solution(int n, String A, String B) { char[] aArray = A.toCharArray(); char[] bArray = B.toCharArray(); int len = aArray.length; char[] aRevArray = new char[len]; for (int i = 0; i < len; i++) { aRevArray[i] = aArray[len-1-i]; } int count = 0; int aaOneNum = 0; int bbOneNum = 0; for (int i = 0; i < len; i++) { int aa = Integer.valueOf(aArray[i]-48); int bb = Integer.valueOf(bArray[i]-48); if (aa + bb == 1) { count ++ ; if(aa==1){ aaOneNum++; }else{ bbOneNum++; } } } int countRev = 0; int aaOneNumRev = 0; int bbOneNumRev = 0; for (int i = 0; i < len; i++) { int aa = Integer.valueOf(aRevArray[i]-48); int bb = Integer.valueOf(bArray[i]-48); if (aa + bb == 1) { countRev ++ ; if(aa==1){ aaOneNumRev++; }else{ bbOneNumRev++; } } } int res1 = count - Math.min(aaOneNum, bbOneNum); int res2 = countRev - Math.min(aaOneNumRev, bbOneNumRev) +1; int res = Math.min(res1, res2); return res; } } 谁能帮我看看为啥AC0呢,我认为100对啊,测试用例也能通过。
全部评论
(0) 回帖