【Codeforces Round #301 (Div. 2) A】 Combination Lock
【链接】 我是链接,点我呀:)
【题意】
【题解】
模拟水题【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
//no pain no gain
int a[N+10],b[N+10],n;
int get_ans(int x,int y){
int temp = x;
int ans = 0;
while (temp!=y){
ans++;
temp--;
if (temp<0) temp = 9;
}
int cnt = 0;
while (x!=y){
cnt++;
x++;
if (x>9) x = 0;
}
ans = min(ans,cnt);
return ans;
}
char s[N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "rt", stdin);
#endif
scanf("%d",&n);
scanf("%s",s+1);
for (int i = 1;i <= n;i++) a[i] = s[i]-'0';
scanf("%s",s+1);
for (int i = 1;i <= n;i++) b[i] = s[i]-'0';
int ans = 0;
for (int i = 1;i <= n;i++)
ans+=get_ans(a[i],b[i]);
printf("%d\n",ans);
return 0;
}