When failed to unlock user account of smart phone, ipad, laptop, you will be unable to access them again. Furthermore, some machines make fun of you.
Mr.Yuan decides to create a new login system “200M” which generates a random number as password when the user tries to access it.
Because it’s almost impossible to login successfully in one try, the user can ask machine whether the password P is greater/less than a certain number x for at most 200 times.
As a CS student, you found the system “200M” has serious security issues.
To show how serious it is, you decided to write a program to hack “200M” for T times.
For each time attacking “200M”, you can make some queries to “200M” and guess the password.
If you guess correctly, the next round will be started. Otherwise, just make more queries and guess until success.
Once the number of query+guess has been more than 200, the login system “200M” will freeze your login account which means you can’t access it again.
Your task is to design a strategy to hack “200M” base on the answer of it and the decision you have made before.
This problem is partial judge. You’re asked to complete functions of class Engineer:
void init(): Initialization when start a new attack.MakeQuery(char* query_str): Make a query (string) to “200M” base on your history.GetAnswer(bool ans): Get the answer from Machine and do something.Query satisfies following format:
"greater", "less", "guess"int"greater 10", "guess 71", "less -22" are legal"Greater 10", "guess 0.5", "less 99999999999", "guess33" are illegal.If you want interact with “200M” by yourself, use the function.cpp below:
#include "function.h"
Engineer::Engineer(){
// TODO
}
Engineer::~Engineer(){
// TODO
}
void Engineer::init(){
// TODO
}
void Engineer::MakeQuery(char* query_str){
// Interactive Version
char op[100];
int x;
scanf("%s %d", op, &x);
sprintf(query_str, "%s %d", op, x);
// Determine the query string by history
// TODO
void Engineer::GetAnswer(bool ans){
// TODO
}
An integer T, denoting the number of attacks.
It’s guaranteed that:
int.It's unnecessary to handle output by yourself.
There’re 2 kind of print function in main.cpp:
printf("..."): print the messages on “stdout”, OJ judges the result by this.fprintf(stderr, "..." ): print the messages on “stderr”, OJ ignores the messages of “stderr” while judging.