Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.util.*;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner scn = new Scanner(System.in);
  5. int n=scn.nextInt();
  6. while(n--!=0){
  7. char str1[]=scn.next().toCharArray(),str2[]=scn.next().toCharArray();
  8. int tot=0;
  9. for(int i=0;i<str1.length;i++){
  10. double a=str1[i]-'0',b=str2[i]-'0';
  11. if(a<b){
  12. double temp=b;
  13. b=a;
  14. a=temp;
  15. }
  16. tot+=Math.abs(a-b)>Math.abs(10-a)+b?(int)Math.abs(10-a)+b:(int)Math.abs(a-b);
  17. }
  18. System.out.println(tot);
  19. }
  20. }
  21. /*題目:ITSA 第53次月賽 [Problem 3] 號碼鎖最少轉動幾次
  22. 作者:1010
  23. 時間:西元 2017 年 2 月 */
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement