540A. Combination Lock

Problem Link

<Source Code>

#include<stdio.h>
#include<string.h>

#include<stdlib.h>
int main()
{
char a[1000],b[1000];long long int mid,n,i,j,res=0,x,y,XX;
scanf("%lld",&n);getchar();
for(i=0;i<n;i++)
    scanf("%c",&a[i]);getchar();
for(j=0;j<n;j++)
    scanf("%c",&b[j]);
res=0,XX=0;mid=0;
for(i=0;i<n;i++)
{
    x=a[i]-'0';
y=b[i]-'0';
mid=x+y;res=abs(x-y);
if(res>=5)
    res=10-res;
XX+=(mid<res)?mid:res;

}
printf("%lld\n",XX);
return 0;
}

		
Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s