Erop's blog

By Erop, 12 years ago, translation, In English

Hello everybody!

An important part of preparing a problem is writng a validator. It's a special program that checks if every test matches all constraints from the problem statement. Writing a validator is as difficult as writing a checker: one can encounter many difficulties with writing it from nothing, some of them have been already mentioned by MikeMirzayanov.

However, checker and validator perform different functions and sometimes it can be not so convinient to use the same library for writing them both. So I'd like you to take a look at the library called strict.h. It was made for writing validators only. The last version of it is avaliable here http://acm.timus.ru/stricth/.

In many problems format of input data has more or less standard form. So one may want a validator for such problems to be as simple as possible but at the same time to be still a correct validator.

All this can be done with strict.h library. This library has already been being used while preparing Ural contests as well as at Timus Online Judge.

Example of validator

Validator for problem 1393. Average Common Prefix from Timus:

#include "strict.h"
using namespace std;

const int MAXLEN = 250000;
const int MINLEN = 2;

int main()
{
    Input in;

    int n = in.readInt(MINLEN, MAXLEN);
    in.readEoln();
    in.readToken(n, n, "A-Z");
    in.readEoln();
    in.readEof();

    return 0;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it