Блог пользователя ldn694

Автор ldn694, история, 4 года назад, По-английски

Hello peoples of codeforces, I just want to ask a question. Recently, I found debugging interactive problems' code manually kinda frustrating. Take this problem as an example. Having to answer the code's queries on my own is really time-consuming and one mistake means typing all over again. But if we could have another code that can simply read the original code's queries and answering them automatically then it would be really useful and convenient, especially when participating in a contest. If the problem was non-interactive, I would simply use files for input and output, but interactive problems require simultaneous interaction between two codes, which makes the solution of using files failed. So I am curious to know how to implement that. I would be so appreciative if someone can provide me a template in C++. Thanks for reading and have a nice day.

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ldn694 (previous revision, new revision, compare).

»
4 года назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

I put all query functions in lambdas. I can easily modify it to return the value from some given data. For example

void solve(){
    int n;
    cin>>n;
    //vector<int> seq(n);
    //cin>>seq;
    auto query = [&](int i,int j){
        cout<<"? "<<i+1<<" "<<j+1<<endl;
        int ans;
        cin>>ans;
        //ans = (seq[i] | seq[j]);
        return ans;
    };
}

Its very easy to switch between local testing and submissions. You can also use #ifdefs, if you have to change a lot. It's perhaps not the best way to test, but I think it is simple enough.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I am looking for a code that can check the original code (the code I would submit). Then I could write a code to generate random tests and check the original one. For example the problem I mentioned in the blog. I want to have a code to simply generate random sequences, run the original code and interact with it, and check whether the sequence that the first code provides are the correct ones. If that is possible, I could automatically check the original one with a lot of random tests and fix the bugs if it gives an incorrect answer. I am sorry if the blog is easily to be misunderstood.

»
4 года назад, # |
Rev. 5   Проголосовать: нравится +4 Проголосовать: не нравится
Code

For this problem, you can write some code like this to check your code