Created
January 4, 2016 16:19
-
-
Save Jack-Saleem/1a27d5ece35b7be675c2 to your computer and use it in GitHub Desktop.
Codeforces 540A CombinationLock program in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class CombinationLock | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner z=new Scanner(System.in); | |
int a=z.nextInt(); | |
String b=z.next(); | |
String c=z.next(); | |
int p1=0; | |
int[] s1=new int[a]; | |
int[] s2=new int[a]; | |
for(int p=0;p<a;p++) | |
s1[p]=Character.getNumericValue(b.charAt(p)); | |
for(int q=0;q<a;q++) | |
s2[q]=Character.getNumericValue(c.charAt(q)); | |
for(int r=0;r<a;r++) | |
{ | |
if(s1[r]>s2[r]) | |
{ | |
if(Math.abs(s1[r]-s2[r])>5) | |
p1=p1+(9-s1[r])+(s2[r]+1); | |
else | |
p1=p1+Math.abs(s1[r]-s2[r]); | |
} | |
else | |
{ | |
if(Math.abs(s1[r]-s2[r])>5) | |
p1=p1+(9-s2[r])+(s1[r]+1); | |
else | |
p1=p1+Math.abs(s1[r]-s2[r]); | |
} | |
} | |
System.out.println(p1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment