Codeforces 540A combination Lock (water problem)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.