Test instructions: Given a string number, indicating a password lock, and then given a string of passwords, ask you to swipe the fewest number of times, the first line into the second row.
Analysis: Very simple, anyway, only 0-9 of this 10 numbers, then is to each number from the slip and inverted slip to find a minimum can, is sliding is the large number of reduction, inverted is the decimal +10-large number.
The code is as follows:
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int MAXN = 1e3 + 5;const int INF = 0x3f3f3f3f ; Char S[maxn];char t[maxn];int main () { int n; CIN >> N; scanf ("%s", s); scanf ("%s", t); int ans = 0; for (int i = 0; i < n; ++i) { int x = s[i]-' 0 '; int y = t[i]-' 0 '; Ans + = min (abs (XY), (min (x, y) +10-max (x, y))%10); } cout << ans << endl; return 0;}
Codeforces 540A combination Lock (water problem)