开发者

How to create reactive tasks for programming competitions?

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜