views:

65

answers:

1

A reactive task is sometimes seen in the IOI programming competition. Unlike batch tasks, reactive solutions take input from another program as well as outputting it. The program typically 'query' the judge program a certain number of times, then output a final answer.

An example

The client program accepts lines one by one, and simply echoes it back. When it encountered a line with "done", it exists immediately.

The client program in Java looks like this:

import java.util.*;
class Main{
  public static void main (String[] args){
     Scanner in = new Scanner(System.in);
     String s;
     while (!(s=in.nextLine()).equals("done"))
        System.out.println(s);
  }
}

The judge program gives the input and processes output from the client program. In this example, it feeds it a predefined input and checks if the client program has echoed it back correctly.

A session might go like this:

Judge       Client
------------------
Hello
            Hello
World
            World
done

I'm having trouble writing the judge program and having it judge the client program. I'd appreciate if someone could write a judge program for my example.

A: 

You get programs to talk to each other via the command prompt.

On windows, you'd write:

java judge | java client

So it's piping the output of judge to the input of client.

That is to say, as long as judge is writing to the standard output stream (which it will) and client is reading from the standard input stream (which yours is) then it will work.

Noon Silk
Yes. Problem is, the client also needs to *write* output to the judge, so it's not completely one way.
directx