Find Your Solution Here

Codeforces

codeforces solution 540A – Combination Lock

Problem link—540A – Combination Lock
/*

Harun-or-Rashid

CSEDU-23rd Batch

*/

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,x,y,cnt=0;
    scanf("%d",&n);
    char s1[n],s2[n];
    scanf("%s",s1);
    scanf("%s",s2);
    for(i=0; i<n; i++)
    {
        x=max(s1[i],s2[i]);
        y=min(s1[i],s2[i]);
        if(x-y<=5)
        {
            cnt+=x-y;
        }
        else
            cnt+=56-x+y-47+1;
    }
    printf("%d\n",cnt);

    return 0;
}

Leave a Reply