-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimumMoves.java
More file actions
50 lines (40 loc) · 1.1 KB
/
MinimumMoves.java
File metadata and controls
50 lines (40 loc) · 1.1 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class MinimumMoves
{
public static void main( String[] args )
{
Scanner s = new Scanner( System.in );
int a = s.nextInt();
List<Integer> aList = new ArrayList<Integer>();
for( int i = 0; i < a; i++ )
{
aList.add( s.nextInt() );
}
int b = s.nextInt();
List<Integer> bList = new ArrayList<Integer>();
for( int i = 0; i < b; i++ )
{
bList.add( s.nextInt() );
}
System.out.println( minimumMoves( aList, bList ) );
}
public static int minimumMoves( List<Integer> a, List<Integer> m )
{
int countOperation = 0;
int n = a.size();
for( int i = 0; i < n; i++ )
{
int numA = a.get( i );
int numM = m.get( i );
while( numA > 0 )
{
countOperation += Math.abs( numA % 10 - numM % 10 );
numA /= 10;
numM /= 10;
}
}
return countOperation;
}
}