ldn694's blog

By ldn694, history, 4 years ago, In English

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.

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it +15 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 years ago, # |
Rev. 5   Vote: I like it +4 Vote: I do not like it
Code

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