Repository navigation
How to judge Interact problem #56
|
最近我在做函数式交互题的时候发现 cph-ng 是具有交互题功能,但是我设置了之后发现会出现collect2报错找不到 main 函数,请问 CPH-NG 是只支持 IO 交互吗,未来会添加函数式交互的支持吗?或者是我的使用问题? |
Answered by
langningchen
Sep 28, 2025
Replies: 2 comments
|
Recently, while working on function-style interactive problems, I noticed that cph-ng has interactive problem support. However, after setting it in the problem's page, I encountered a compiler error from collect2 saying it couldn’t find the main function. So I’d like to ask: does cph-ng only support I/O-style interactive problems? Will function-style interactive support be added in the future, or is this an issue with my usage? |
0 replies
|
We use Click to expand the example of I/O interaction// source.cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int l = 1, r = 1000000000;
while (true)
{
int mid = l + (r - l) / 2;
cout << mid << endl;
cout.flush();
int res;
cin >> res;
if (res == 0)
break;
else if (res == -1)
l = mid + 1;
else
r = mid - 1;
}
return 0;
}// spj.cpp
#include "testlib.h"
using namespace std;
int main(int argc, char **argv)
{
registerInteraction(argc, argv);
int n = inf.readInt();
cout.flush();
int left = 50;
bool found = false;
while (left > 0 && !found)
{
left--;
int a = ouf.readInt(1, 1000000000);
if (a < n)
cout << -1 << endl;
else if (a > n)
cout << 1 << endl;
else
cout << 0 << endl, found = true;
cout.flush();
}
if (!found)
quitf(_wa, "couldn't guess the number with 50 questions");
ouf.seekEoln();
ouf.readEof();
quitf(_ok, "guessed the number with %d questions!", 50 - left);
} |
0 replies
Answer selected by
langningchen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We use
testlibfor standard I/O interaction. For function interaction, you can try to#include "grader.cpp".Click to expand the example of I/O interaction