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

×

Can someone please explain why codechef compiler is declaring this code has a wrong output while i am getting the correct one.

I am using IntelliJ as my platform. The question can be found here:https:"www.codechef.com/problems/SNAKPROC."

My Code:
import java.util.Scanner;
class SnakeCounter {
int l;
int h=-1;int t=-1;
int k=-1;
String arr[];
void accept()
{
int co=-1;
Scanner sc=new Scanner(System.in);
int T;
T=sc.nextInt();
sc.nextLine();
arr=new String[T];
while(T!=0)
{
l=sc.nextInt();
sc.nextLine();
String s=sc.nextLine();
int c=-1;
for(int i=0;i<l;i++)<br> {
if(s.charAt(i)=='H')
{
h=h+1;
if(c==1)
{
k=0;
break;
}
c=1;
}
if(s.charAt(i)=='T')
{
t=t+1;
if(c==0)
{
k=0;
break;
}
c=0;
}
}
if(k==0)
arr[++co]="Invalid";
else if(h!=t)
arr[++co]="Invalid";
else
arr[++co]="Valid";
T=T-1;
h=-1;t=-1;k=-1;c=-1;
}
}
void display()
{
for(int i=0;i<arr.length;i++)<br> System.out.println(arr[i]);
}
public static void main(String args[])
{
SnakeCounter obj=new SnakeCounter();
obj.accept();
obj.display();
}
}

AND it is giving the correct output for the given input example.

asked 29 Sep '18, 14:19

rishav_258's gravatar image

0★rishav_258
1
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:

×1,302
×678

question asked: 29 Sep '18, 14:19

question was seen: 64 times

last updated: 29 Sep '18, 14:19