Created
January 5, 2016 18:59
-
-
Save Jack-Saleem/9ffbb42a53dc07e2cc27 to your computer and use it in GitHub Desktop.
Codeforces 146A LuckyTicket 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.math.BigInteger; | |
import java.util.Scanner; | |
public class LuckyTicket | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner z=new Scanner(System.in); | |
int n=z.nextInt(); | |
String b=z.next(); | |
BigInteger big=new BigInteger(b); | |
boolean flag=true; | |
if(b.length()==big.toString().length()){ | |
for(int j=0;j<=9;j++){ | |
if(j!=4 && j!=7){ | |
if(big.toString().contains(String.valueOf(j))){ | |
System.out.println("NO"); | |
flag=false;break; | |
} | |
} | |
} | |
}else{ | |
System.out.println("NO");flag=false; | |
} | |
int temp=0,xtemp=0; | |
int a[]=new int[n]; | |
if(flag){ | |
for(int i=1;i<=n/2;i++){ | |
a[i-1]=Integer.parseInt(big.toString().substring(i-1, i)); | |
temp+=a[i-1]; | |
} | |
for(int i=n/2+1;i<=n;i++){ | |
a[i-1]=Integer.parseInt(big.toString().substring(i-1, i)); | |
xtemp+=a[i-1]; | |
} | |
if(temp==xtemp) | |
System.out.println("YES"); | |
else | |
System.out.println("NO"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment