We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is really an amazing idea. Doing reverse engineering.
Rather i tried checking at each step whetehr it follows all rules or not. and it is so messed up. If anyone can guide me on how to improve code. I mean want to keep the logic same but if at some places i am doing redundant work, or unnecesary conditions or anything like that. It will be great help.
staticvoidseparateNumbers(Strings){if(s.length()<2)System.out.println("NO");elseif(s.charAt(0)=='0')System.out.println("NO");else{intcheck_len=1;booleanflag=true;//flag is for checking whether they are consecutive numbers or notbooleanflag2=false;//flag2 is to check wether we increaed check_len somewhere in middle due to number of all nineswhile(check_len<=s.length()/2){flag=true;flag2=false;inti=check_len;longval1=Long.parseLong(s.substring(0,check_len));for(i=check_len;i<s.length()-check_len+1;i+=check_len){if(val1AllNine(val1)){check_len++;flag2=true;}longval2=Long.parseLong(s.substring(i,i+check_len));if(val2-val1!=1||s.charAt(i)=='0'){flag=false;break;}elseval1=val2;//going on next piece of string}if(i==s.length()&&flag)break;else{if(!flag2)check_len++;//increase check_len only if it not increased half way in last iteration}}if(flag&&!flag2)System.out.println("YES "+s.substring(0,check_len));elseif(flag&&flag2)System.out.println("YES "+s.substring(0,check_len-1));elseSystem.out.println("NO");}}staticbooleanval1AllNine(longv1){while(v1>=9){if(v1%10<9)returnfalse;v1=v1/10;}if(v1<9&&v1>0)returnfalse;elsereturntrue;}
Separate the Numbers
You are viewing a single comment's thread. Return to all comments →
This is really an amazing idea. Doing reverse engineering. Rather i tried checking at each step whetehr it follows all rules or not. and it is so messed up. If anyone can guide me on how to improve code. I mean want to keep the logic same but if at some places i am doing redundant work, or unnecesary conditions or anything like that. It will be great help.