You are not logged in. Please login at www.codechef.com to post your questions!

×

NEED HELP FOR DEBUGGING

I am trying to solve SNELECT problem. It is working fine in my pc for all possible test cases present in question and also which i could think. But it is still showing runtime error(NZEC) during submission. MY CODE:

import java.io.*;
import java.util.*;
class RIPsnakes
{
public static void main(String args[])throws IOException
{

  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  int T=Integer.parseInt(br.readLine());
  for(int j=1;j<=T;j++){
  String a=br.readLine();
  char []A=a.toCharArray();
  int snakes=0; int mongoose=0;

 for(int i=0;i<A.length;i++){if(A[i]=='s'){snakes++;  }else{mongoose++;  } }

  for(int i=0; i<A.length;i++)
  {if(A[i]=='m'){
      if(i==0){if(A[1]=='s'){snakes--; A[1]='_' ;} continue;}
     else if(i==A.length-1){if(A[i-1]=='s'){snakes--; A[i-1]='_';} break;}
     else if(A[i-1]=='s'){snakes--; A[i-1]='_'; continue;}
     else if(A[i+1]=='s'){snakes--; A[i+1]='_';  continue;}

    }

}
if(snakes>mongoose){System.out.println("snakes");}  
else if(snakes==mongoose){System.out.println("tie");}
else { System.out.println("mongooses");     }}}}

asked 11 Aug, 19:33

humurabbi's gravatar image

0★humurabbi
173
accept rate: 0%

edited 11 Aug, 19:37


if(i==0){if(A[1]=='s'){snakes--; A[1]='_' ;} continue;}

What if my input is of size 1? Like only 's' and 'm'? A[1] will not exist then and this should give you NZEC.

link

answered 11 Aug, 20:05

vijju123's gravatar image

4★vijju123
7.4k212
accept rate: 17%

Try debugging on your own

You can do it mate! This is the only way to improve

Though vijju123 has corrected your code

link

answered 13 Aug, 01:19

anmolmishra's gravatar image

2★anmolmishra
112
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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:

×375
×106

question asked: 11 Aug, 19:33

question was seen: 83 times

last updated: 13 Aug, 01:19