#include<iostream>
#include<ctime>
using namespace std;
int main() {
srand(time(0));
int boom = rand() % 100;
int guess;
int upperbound = 100;
int lowerbound = 0;
for (int i = 0; i < 10; i++) {
cin >> guess;
if (guess < upperbound && guess > lowerbound) {
if (guess == boom) {
cout << "boom";
break;
} else if (guess < boom) {
lowerbound = guess;
cout << lowerbound << "~" << upperbound << endl;
} else {
upperbound = guess;
cout << lowerbound << "~" << upperbound << endl;
}
} else {
cout << "out of range" << endl;
i--;
}
}
return 0;
}
不知道具体规则,写了个框架
#include<ctime>
using namespace std;
int main() {
srand(time(0));
int boom = rand() % 100;
int guess;
int upperbound = 100;
int lowerbound = 0;
for (int i = 0; i < 10; i++) {
cin >> guess;
if (guess < upperbound && guess > lowerbound) {
if (guess == boom) {
cout << "boom";
break;
} else if (guess < boom) {
lowerbound = guess;
cout << lowerbound << "~" << upperbound << endl;
} else {
upperbound = guess;
cout << lowerbound << "~" << upperbound << endl;
}
} else {
cout << "out of range" << endl;
i--;
}
}
return 0;
}
不知道具体规则,写了个框架