PAJAPONG -why my code is giving wrong answer

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[]args) throws java.lang.Exception,
IOException
{
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long T = Integer.parseInt(br.readLine());

  while (T > 0)
{
   int c=Integer.parseInt(br.readLine()); 
  int p=Integer.parseInt(br.readLine()); 
    int k=Integer.parseInt(br.readLine()); 
    int sum=c+p;                                 
    
    int div=sum/k;
    if(div%2==0)
    System.out.println("Chef");
     
     else
   
      System.out.println("Paja");
      
    
  
  
  T--;
}
}
catch (Exception e)
{
  return;
}

}
}

Is it because you don’t understand the meaning of the problem?

is my logic wrong???

You can try some small examples for yourself.

when i am taking input with Scanner object it it giving right answer,but when i use BufferedReader it is giving wrong answer?

You can try to output the numbers you read in.

i have tried that too,still dont understand?

When using Scanner, you also need to take care of the \n that is at the end of an input line.

my other code is giving right answer,but what is the difference?

int t = sc.nextInt();
while(t-- !=0)
{
int c = sc.nextInt();
int p = sc.nextInt();
int k = sc.nextInt();
int sum = c+p;
int div = sum/k;
if(div%2==0)
System.out.println(“Chef”);
else
System.out.println(“Paja”);
}

Scanner doesn’t work correctly when you have inputs with spaces and newlines so you will need some workarounds. If you run your code, you will see that it waits for input after the second line has been entered. It’s better to use BufferedReader which is faster (so no TLE if your algorithm is optimal) and has no weird issues. Use the code mentioned here (3rd one)

but when i am using Scanner it it giving right answer and when i using BufferedReader it is giving wrong answer

lol then I read your other post wrong! Anyway, you are reading entire lines into those three variables instead of only an integer. The second line of input has three numbers separated by a space.

that dosent matter ,still that scanner code is giving right answer

int t = sc.nextInt();
while(t-- !=0)
{
int c = sc.nextInt();
int p = sc.nextInt();
int k = sc.nextInt();
int sum = c+p;
int div = sum/k;
if(div%2==0)
System.out.println(“Chef”);
else
System.out.println(“Paja”);

int c=Integer.parseInt(br.readLine());

This will read the test case lines of the input (1 3 3). You are trying to parse an entire line(with spaces) into an integer.

thanks,man:::+1::+1::+1::+1:

BTW, you have already solved the problem, haven’t you? Your algorithm is correct so it doesn’t matter now if the BufferedReader code does not work. Move on to the other problems.