Combination Lock (UVA 13049) by aizu_f
Contest: 3738    RunID: 20173760    Status: Accepted    Date: Sat Oct 14 14:22:29 JST 2017


#include <iostream>

using namespace std;

int solve(string init, string target, int n){
	int steps = 0;
	for(int i = 0; i < n; ++i){
		int val = abs(target[i] - init[i]);
		if(val <= 5) steps += val;
		else steps += 10 - val;
	}
	return steps;
}

int main(){
	int t;
	cin >> t;
	int i = 1;
	while(t--){
		int n;
		string init, target;
		cin >> n >> init >> target;
		cout << "Case " << i++ << ": " << solve(init, target, n) << endl;
	}
	return 0;
}