showing wrong answer when it is working f9 on windows 7

Chef-jumping ques

Following is my code, which is a success on ideone.com, the onl9 compiler:

public class Main

{

public static void main (java.lang.String[] args) throws java.io.IOException

{

if(args.length != 2)

{

java.lang.System.exit(0);

}

java.io.BufferedReader br=new java.io.BufferedReader(new

java.io.InputStreamReader(java.lang.System.in));

java.lang.String str=br.readLine();

if(str.length() > 19 || str.length() < 1)

{

java.lang.System.exit(0);

}

java.lang.String num="";

java.io.FileOutputStream foutinp=new java.io.FileOutputStream(args[0]);

byte b[]=str.getBytes();

foutinp.write(b);

foutinp.close();

java.io.File f=new java.io.File(args[0]);

if(f.exists())

{

java.io.FileInputStream fininp=new java.io.FileInputStream(args[0]);

int ch;

while((ch=fininp.read()) != -1)

{

num+=(char)ch;

}

int len=num.length();

for(int i=0;i<len;i++)

{

if(!(num.charAt(i) >= ‘0’ && num.charAt(i) <= ‘9’))

{

java.lang.System.exit(0);

}

}

if(len!=1)

{

num=num.charAt(len-2)+""+num.charAt(len-1);

}

else

{

num=""+num.charAt(len-1);

}

int no=java.lang.Integer.parseInt(num);

java.lang.String msg;

if(no==0)

{

msg=“yes”;

}

else

{

no=no%6;

if(no==0)

{

msg=“yes”;

}

else

{

no=no-1;

if(no==0)

{

msg=“yes”;

}

else

{

no=no-2;

if(no==0)

{

msg=“yes”;

}

else

{

msg=“no”;

}

}

}

}

java.io.FileOutputStream foutop=new java.io.FileOutputStream(args[1]);

byte bt[]=msg.getBytes();

foutop.write(bt);

foutop.close();

java.io.File f2=new java.io.File(args[1]);

if(f2.exists())

{

java.io.FileInputStream fin=new java.io.FileInputStream(f2);

msg="";

while((ch=fin.read()) != -1)

{

msg+=(char)ch;

}

java.lang.System.out.println(msg);

}

else

{

java.lang.System.exit(0);

}

}

else

{

java.lang.System.exit(0);

}

}

}

hey…plz can som1 help me by providing solution to this prob

2 Likes

Simple solution in C++ :

 #include <iostream>
using namespace std;

int main() {
	long long x ;
	cin >> x ;
	long long y = x%6 ;
	if ( y == 0 || y == 1 || y == 3 )
	cout<<"yes\n";
	else
	cout<<"no\n" ;

	return 0;
}

could you please indent your code.
Its really tough to read the code you have written without indentation

1 Like

@vinitkp just copy this code in sublime and u can indent it there very easily.If u really want to help debugging her code,atleast u can do this.:slight_smile:

2 Likes

plz can someone provide me a solution in java language…as i want to undrstnd the format that codechef accepts…

The solution is simple if jump modules 6 is 0 or 1 or 3 then its possible otherwise not

import java.math.*;

import java.util.*;

class Ideone {

	public static void main(String args[]) {
		Scanner x = new Scanner(System.in);
		String y = x.next();
		BigInteger b = new BigInteger(y);
		b=b.mod(new BigInteger("6"));
		String a= b.toString();
		if(a.equals("0")||a.equals("1") || a.equals("3"))
		System.out.println("yes");
		else
		System.out.println("no");
	}

}

thank u sanzzzay

u are welcome @noopur1991:slight_smile: feel free to ask doubt …