You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result { public static boolean separateNumbers(String s,String s1,int i,int j,String comp,String trace) { if(j>s.length()) { return false; } else { comp=s1; s1=s.substring(i,j); if(comp==null) trace=s1; if(comp!=null&&(Long.valueOf(comp)+1)!=Long.valueOf(s1)) return false; else if(comp!=null&&((Long.valueOf(comp)+1)==Long.valueOf(s1))&&(j+(Long.toString(Long.valueOf(s1)+1).length()))>s.length()&&j==s.length()) { System.out.println("YES "+trace); return true; } i+=s1.length(); j+=(Long.toString(Long.valueOf(s1)+1).length()); return separateNumbers(s, s1, i, j,comp,trace); } } } public class Solution { public static void main(String args[])throws Exception { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int k=1;k<=n;k++) { int flag=0; String str=sc.next(); int max=str.length()/2; for(int i=1;i<=max;i++) { if (Result.separateNumbers(str,null,0,i,null,null)==true) { flag=1; } } if(flag==0) System.out.println("NO"); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Separate the Numbers
You are viewing a single comment's thread. Return to all comments →