求助关于testlib的Interactor
  • 板块学术版
  • 楼主Fresca
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/9 17:37
  • 上次更新2024/8/9 18:54:40
查看原帖
求助关于testlib的Interactor
431265
Fresca楼主2024/8/9 17:37

在写好了如下这样一个interactor应该怎么使用,对它进行编译之后可传的参数只有

<input-file> <output-file> [<answer-file> [<report-file> [<-appes>]]]

求助大佬我应该如何进行交互

#include "../testlib.h"
#include <iostream>

int main(int argc, char **argv)
{
    registerInteraction(argc, argv);
    int T = inf.readInt();
    for (int i = 1; i <= T; ++i)
    {
        std::cout.flush();
        int x = inf.readInt();
        int left = 8, ans = -1;
        bool found = false;
        while (left > 0)
        {
            left--;
            char op = inf.readChar();
            if (op == '!')
            {
                int ans = ouf.readInt(1, 1000);
                found = true;
                break;
            }
            else
            {
                if (left == 0)
                    break;
                int a = ouf.readInt(1, 1000);
                int b = ouf.readInt(1, 1000);
                if (a >= x)
                    ++a;
                if (b >= x)
                    ++b;
                std::cout << a * b << std::endl;
            }
        }
        if (!found)
        {
            quitf(_wa, "couldn't guess the number with 7 questions on testcase %d", i);
            ouf.readEof();
        }
        else if (ans != x)
        {
            quitf(_wa, "wrong answer on testcase %d\nexpected answer: %d\nOutput: %d", i, x, ans);
            ouf.readEof();
        }
    }
    quitf(_ok, "");
    ouf.readEof();
    return 0;
}

2024/8/9 17:37
加载中...