-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf_round879_div2_B.java
35 lines (34 loc) · 1.02 KB
/
cf_round879_div2_B.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
public class cf_round879_div2_B {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t --> 0){
String l = sc.next();
String r = sc.next();
String lnew = "";
String rnew = "";
// while(l.length() <= r.length()){
// l = "0"+l;
// }
// while(r.length() <= l.length()){
// r = "0"+r;
// }
int ans = 0;
boolean append9 = false;
for(int i = 0;i<l.length();i++){
if(append9){
ans += 9;
continue;
}
if(l.charAt(i) != r.charAt(i)){
int t1 = l.charAt(i) - '0';
int t2 = r.charAt(i) - '0';
ans += Math.abs(t1 - t2);
append9 = true;
}
}
System.out.println(ans);
}
}
}