Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- int n=scn.nextInt();
- while(n--!=0){
- char str1[]=scn.next().toCharArray(),str2[]=scn.next().toCharArray();
- int tot=0;
- for(int i=0;i<str1.length;i++){
- double a=str1[i]-'0',b=str2[i]-'0';
- if(a<b){
- double temp=b;
- b=a;
- a=temp;
- }
- tot+=Math.abs(a-b)>Math.abs(10-a)+b?(int)Math.abs(10-a)+b:(int)Math.abs(a-b);
- }
- System.out.println(tot);
- }
- }
- /*題目:ITSA 第53次月賽 [Problem 3] 號碼鎖最少轉動幾次
- 作者:1010
- 時間:西元 2017 年 2 月 */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement