-
Notifications
You must be signed in to change notification settings - Fork 4
/
main__Interactor.cpp
52 lines (45 loc) · 1.72 KB
/
main__Interactor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
uniform_int_distribution<int> uid(l, r);
return uid(rng);
}
// ALWAYS USE `endl` FOR FLUSHING THE OUTPUT, NOT `\n`
int main() {
// Generate random test case
int answer = rand(1,100);
int asked_questions = 0;
while (true) {
char user_response_type;
int response;
// Take the user's response as input
cin >> user_response_type >> response;
// Outputting this to stderr for debugging purposes
cerr << user_response_type << " " << response << endl;
asked_questions++;
if (asked_questions > 100) {
cerr << "Too many questions" << endl; // Outputting every verdict to stderr
return 1; // return 1 in case of FAILURE
}
if (user_response_type == '?') {
// Give proper response to stdout
// FOR INTERACTING WITH USER, GIVE THE RESPONSE USING `cout`, FOR GIVING VERDICT, USE `cerr`
int interactor_response;
// ...
cout << interactor_response << endl;
cerr << interactor_response << endl; // Outputting this to stderr for debugging purposes
} else if (user_response_type == '!') {
if (response == answer) {
cerr << "Correct solution" << endl;
break;
} else {
cerr << "Incorrect solution." << endl;
return 1; // return 1 in case of FAILURE
}
}
}
// Output the correct answer and return 0 (SUCCESS)
cerr << "Correct Answer: " << answer << endl;
return 0;
}