Created
January 5, 2016 16:49
-
-
Save Jack-Saleem/5c8a9af6c47f4b6044c2 to your computer and use it in GitHub Desktop.
codeforces 320A MagicNumbers 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 MagicNumbers | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner z=new Scanner(System.in); | |
int n=z.nextInt(); | |
boolean flag=true; | |
for(int i=0;i<=9;i++) | |
{ | |
if(i!=4 && i!=1) | |
{ | |
if(Integer.toString(n).contains(String.valueOf(i))){ | |
System.out.println("NO"); | |
flag=false; | |
break; | |
} | |
} | |
} | |
if(flag) | |
{ | |
if(Integer.toString(n).replaceAll("144", "").replaceAll("14", "").replaceAll("1", "").length()!=0 || Integer.toString(n).contains("444")) | |
System.out.println("NO"); | |
else | |
System.out.println("YES"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment