Codeforces Combination Lock

来源:互联网 发布:淘宝网卫裤 编辑:程序博客网 时间:2024/05/22 06:17


import java.util.Scanner;public class CombinationLock {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();char[] ch1 = scanner.next().toCharArray();char[] ch2 = scanner.next().toCharArray();int count = 0;for(int i = 0; i < n; i++) {int c1 = ch1[i] - '0';int c2 = ch2[i] - '0';if(c1 >= c2) {count += Math.min(9 - c1 + 1 + c2, c1 - c2);} else {count += Math.min(9 - c2 + 1 + c1, c2 - c1);}}System.out.println(count);}}


原创粉丝点击