English 中文(简体)
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.





相关问题
IConnectableObservables in Rx

Can someone explain the differences between an Observable and a ConnectableObservable? The Rx Extensions documentation is very sparse and I don t understand in what cases the ConnectableObservable is ...

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 ...

Is the Reactive Framework (RX) available for use in Mono yet?

Been searching but the only thing I found was http://evain.net/blog/articles/2009/07/30/rebasing-system-reactive-to-the-net-clr which I got to work, but it feels like there should be a simpler way, ...

Using MonadPlus in FRP.Reactive.FieldTrip

I m studying FRP at this moment through FieldTrip adaptor. And hit the problem with strange way of frames scheduling and integration. So now I m trying to build own marker Event for aligning Behaviour ...

Examples of useful or non-trival dual interfaces

Recently Erik Meijer and others have show how IObservable/IObserver is the dual of IEnumerable/IEnumerator. The fact that they are dual means that any operation on one interface is valid on the other, ...

Reactive Extensions (Rx) + MVVM =?

One of the main examples being used to explain the power of Reactive Extensions (Rx) is combining existing mouse events into a new event representing deltas during mouse drag: var mouseMoves = from ...

热门标签