Combination Lock (UVA 13049) by UKUNICHIA
Contest: 3738    RunID: 20173538    Status: Accepted    Date: Sat Oct 14 13:41:11 JST 2017


#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  int T;
  cin>>T;
  for(int t=1;t<=T;t++){
    cout<<"Case "<<t<<": ";
    int n;
    string s1,s2;
    cin>>n>>s1>>s2;
    auto calc=[](int i,int j){
      if(i>j) swap(i,j);
      return min(j-i,10+i-j);
    };
    int ans=0;
    for(int i=0;i<n;i++)
      ans+=calc(s1[i]-'0',s2[i]-'0');
    cout<<ans<<endl;
  }
  
  return 0;
}