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

×

If a number of test cases isn't provided, when should my program stop reading input?

When should my program stop reading input for problems without multiple test cases?

asked 22 Mar '13, 16:43

rudreshwar's gravatar image

1★rudreshwar
457192531
accept rate: 50%


Some problems do not have multiple test cases, and are instead judged by testing your code multiple times on different input files. If the problem statement does not say there are multiple cases, do not assume there are.

Other problems mention multiple test cases, but don't provide any limits on how many there could be. Your program should stop at the end of the input file. All programming languages have a way of testing this; for example, in Java, a BufferedReader's readLine() method will return null. In C++, scanf returns the number of items successfully matched; EOF if it reaches the end of the file.

Read your programming language's documentation to find out what it returns.

If you choose to test your program without the redirection method mentioned earlier, you can generate an EOF (end-of-file) character by pressing Ctrl-Z.

link

answered 22 Mar '13, 16:43

admin's gravatar image

0★admin ♦♦
19.6k349497539
accept rate: 35%

In C++, while(cin>>n)

To terminate the input, you can use Ctrl+Z

link

answered 20 Aug '15, 22:45

anuragyd22's gravatar image

2★anuragyd22
262
accept rate: 50%

 used in C/C++

 while(scanf("%d",&n)!=EOF){
   //your code is here
  }

HAPPY CODING

link

answered 21 Aug '15, 02:32

rcsldav2017's gravatar image

5★rcsldav2017
1.1k1229
accept rate: 6%

import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.00");
final double ch=0.50f ;
int WdAmnt =input.nextInt();
Double PrevBalnc=input.nextDouble();
boolean flag = false;
if(WdAmnt%5 ==0 && WdAmnt<=2000. && PrevBalnc <=2000.00 && WdAmnt>0 && PrevBalnc>=0.00)
    flag=true;
else 
    flag=false;
if(WdAmnt!=0 && WdAmnt<=PrevBalnc && flag)
{
    PrevBalnc=PrevBalnc-(WdAmnt+ch);
}
System.out.println( df.format(PrevBalnc));
}
}

whats wrong withis code?

link

answered 26 Mar '15, 11:00

rydar's gravatar image

0★rydar
11
accept rate: 0%

edited 21 Aug '15, 00:10

ravi0213's gravatar image

4★ravi0213
2.2k41324

1

Edit it and post it as a code. I don't think anyone can understand this as it is. ( Take EDIT, Select your code, and press Ctrl + k if you're on Windows, or look at the options on the EDIT and you will see code sample )

(26 Mar '15, 11:04) arun_as1★
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:

×206

question asked: 22 Mar '13, 16:43

question was seen: 10,096 times

last updated: 21 Aug '15, 02:32