贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

题目传送门

 /*
贪心水题:累加到目标数字的距离,两头找取最小值
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
char s[MAXN], t[MAXN]; int main(void) //Codeforces Round #301 (Div. 2) A. Combination Lock
{
//freopen ("A.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
scanf ("%s", &s);
getchar ();
scanf ("%s", &t); int ans = ;
for (int i=; i<n; ++i)
{
int tmp = abs (t[i]-s[i]);
ans += min (tmp, - tmp);
} printf ("%d\n", ans);
} return ;
}
上一篇:Weak References


下一篇:Productivity tips, tricks and hacks for academics (2015 edition)