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

×

Unable to submit the solution to a problem

I have written the code to the following problem

The output I am getting is correct but still it shows wrong answer.I have read FAQs but still no nuccess.Where I am doing wrong.(I am a new user to codechef and joined today only)

Here is my code

    import java.io.*;

class abc
{
    public static void main(String args[])
    {
        try{
                    String num;
                    BufferedReader in=new BufferedReader(new FileReader("in.txt"));
                    BufferedWriter out=new BufferedWriter(new FileWriter("out.txt"));

                    while((num=in.readLine())!=null)
                    {
                        if(Integer.parseInt(num)==42)
                            break;
                        else
                            out.write(num+"\n");
                    }
                    in.close();
                    out.close();
        }catch(Exception e)
        {
            System.out.println("File not found");
        }
    }
}

asked 01 Oct '13, 23:42

codernavi18's gravatar image

2★codernavi18
112
accept rate: 0%


You missed that program have to read from stdin - http://www.codechef.com/wiki/faq#How_should_I_test_my_program

link

answered 01 Oct '13, 23:47

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

@codernavi18 : Who told you that input will be available in file named "in.txt" and that you have to create a output file and that you can print messages .
You have read your input from Standard Input
i.e write , BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
And write your output to standard output
i.e. write , BufferedWriter out=new BufferedWriter(System.out);
General Tip : You should not print any messages also , you can assume input to match constraints given in the problem and your output should match exactly the format mentioned in problem statement .

link

answered 01 Oct '13, 23:47

vineetpaliwal's gravatar image

6★vineetpaliwal
12.4k47107171
accept rate: 12%

@codernavi18 Read the sample solutions, especially, sample solution in Java, to get a feel of how problem solving is done in codechef.

link

answered 02 Oct '13, 09:41

tijoforyou's gravatar image

2★tijoforyou
4.2k52364
accept rate: 15%

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:

×2,319
×335

question asked: 01 Oct '13, 23:42

question was seen: 1,599 times

last updated: 02 Oct '13, 09:41