@Yezi.press
简单猜数字游戏
随机生成 1~100 之间的整数,通过输入来猜数字大小
课堂示例更新于 2026年8月19日 12:57#游戏#二分
C++19 行380 Bytes
#include <bits/stdc++.h>
using namespace std;
int main() {
srand(time(0));
int a, cnt = 0, r = rand() % 100 + 1;
while (true) {
cin >> a;
cnt++;
if (a > r) cout << "猜大了" << endl;
else if (a < r) cout << "猜小了" << endl;
else break;
}
cout << "猜对了!共猜了" << cnt << "次";
return 0;
}