Last active
July 22, 2017 10:35
-
-
Save likejazz/dc5b530affdc7a90aff34eea9bfa89ab to your computer and use it in GitHub Desktop.
Minimum Moves
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int diff = 0; | |
// C++ get each digit in integer | |
// https://stackoverflow.com/a/4615187/3513266 | |
void calc_each_moves(int a, int m) { | |
// the variable `a` is used as a reference. | |
if (a >= 10) | |
calc_each_moves(a / 10, m / 10); | |
int ai = a % 10; | |
int mi = m % 10; | |
diff += abs(ai - mi); | |
} | |
int main() { | |
int an, mn; | |
// inputs for Andrea's array. | |
cin >> an; | |
int a[an]; | |
for (int i = 0; i < an; i++) { | |
cin >> a[i]; | |
} | |
// inputs for Maria's array. | |
cin >> mn; | |
int m[mn]; | |
for (int i = 0; i < mn; i++) { | |
cin >> m[i]; | |
} | |
// calculate the each moves. | |
for (int i = 0; i < an; i++) { | |
calc_each_moves(a[i], m[i]); | |
} | |
// print the whole moves. | |
cout << diff << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment