#include <iostream>
#include <random>
#include <time.h>
#include <set>
using namespace std;
double f1(double a)
{
return a / 30;
}
int main()
{
clock_t start, finish; // 挂钟时间
double t = 0;
int f = 0;
random_device rd; // 用于获得随机种子
mt19937 gen1(rd()); // 以随机种子初始化随机数生成器
mt19937 gen2(rd());
mt19937 gen3(rd());
uniform_int_distribution<int> dist1(10, 99); // 生成 [10, 99] 范围内的整数
uniform_int_distribution<int> dist2(1, 4); // 生成 [1, 4] 范围内的整数
uniform_real_distribution<double> dist3(10.0000000, 99.00000000);
uniform_real_distribution<double> dist4(1.0000000, 4.000000);
set<int> generatedNumbers; // 存储已经生成的随机数
int a[31] = { 0 };
for (int i = 0; i < 30; i++)
{
int randomNum1, randomNum2, randomNum3, n;
do
{
randomNum1 = dist1(gen1); // 生成随机数
randomNum2 = dist1(gen2);
randomNum3 = dist2(gen3);
} while (generatedNumbers.count(randomNum1) || generatedNumbers.count(randomNum2) || generatedNumbers.count(randomNum3));
generatedNumbers.insert(randomNum1);
generatedNumbers.insert(randomNum2);
generatedNumbers.insert(randomNum3);
double GameTime = 1000; // 游戏时间
double gametime; // 用户所用时间
if (randomNum3 == 1)
{
n = randomNum1 + randomNum2;
cout << i + 1 << " " << randomNum1;
cout << "+";
cout << randomNum2 << "=" << endl;
}
if (randomNum3 == 2)
{
n = randomNum1 - randomNum2;
if (n < 0)
{
cout << i + 1 << " " << randomNum2;
cout << "-";
cout << randomNum1 << "=" << endl;
n = randomNum2 - randomNum1;
}
else
{
cout << i + 1 << " " << randomNum1;
cout << "-";
cout << randomNum2 << "=" << endl;
n = randomNum1 - randomNum2;
}
}
if (randomNum3 == 3)
{
n = randomNum1 * randomNum2;
while (n >= 1000)
{
n = randomNum1 * randomNum2;
randomNum1--;
randomNum2--;
}
n = randomNum1 * randomNum2;
cout << i + 1 << " " << randomNum1;
cout << "*";
cout << randomNum2 << "=" << endl;
}
if (randomNum3 == 4)
{
do
{
randomNum1 = dist3(gen1); // 生成随机数
randomNum2 = dist4(gen2);
} while (randomNum1 % randomNum2 != 0 && randomNum1 < randomNum2 && randomNum1 != 0 && randomNum2 != 0);
n = randomNum1 / randomNum2;
cout << i + 1 << " " << randomNum1 << "/" << randomNum2 << "=" << endl;
}
start = clock();
cin >> a[i];
finish = clock();
gametime = (double)(finish - start) / CLOCKS_PER_SEC;
if (gametime >= GameTime)
{
cout << "很遗憾,未能在规定时间内得出答案 正确结果" << n << endl;
f++;
continue;
}
if (a[i] == n)
{
cout << "true" << endl;
t++;
}
else
{
cout << "false 正确结果 " << n << endl;
f++;
}
}
cout << "错题数:" << f << endl;
cout << "正确率:" << f1(t) << endl;
return 0;
}