×

# Run Time Error (NZEC) Problem

 0 The program below runs smooth on IDE but when I submit it to Codechef it returns "Runtime Error(NZEC)" message. The function of this program is to take in strings consisting of 0's and 1's as input and to determine if all the 1's in the string occur together or not and return "YES" or "NO' accordingly.(For example(01111100-YES; 011001-NO)). The link to the Codechef question is here :Bear and Segment 01 The code is as given below:  import java.util.Scanner; class Check { public static void main(String args[]) { Scanner p=new Scanner(System.in); int a=p.nextInt(); for(int i=1;i<=a;i++) //This loop takes in the desired number of test cases { long b=p.nextInt(); if(b==0) //If string consists of only zeroes, this statement returns NO { System.out.println("NO"); } for(int j=1;b>0;j++) //This loop determine's the first occurrence of 1 in the string { long c=b%10; if(c==0) { b=b/10; } if(c==1) { break; } } for(int k=1;b>0;k++) //This loop determines the last occurrence of 1 and whether 0 occurs between them { long d=b%10; if(d==0) { System.out.println("NO"); break; } b=(b-d)/10; if(d==1&&b!=0) { continue; } if(d==1&&b==0) { System.out.println("YES"); } } } } } I cannot determine the cause of run time error given by Codechef code tester. Please help me out.  asked 29 Jun '17, 15:13 7●2 accept rate: 0%

 0 You are taking the input as long! But dear, the string can cross 50 digits, and hence the maximum capacity of long. Long can hold till ~10^18. But string can be upto 50 digits, meaning roughly 1.1111111111 x 10^50. You need to store it in a string and iterate through it. Else your code will give a Mismatch input exception or something when it encounters a string of length >18. answered 29 Jun '17, 16:54 15.5k●1●20●66 accept rate: 18%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,471
×545
×354
×191

question asked: 29 Jun '17, 15:13

question was seen: 276 times

last updated: 29 Jun '17, 16:54