数学老师教我们玩的,复刻了一下
不知道玩法的朋友们可以看 这里
以下是完整代码:
#include <windows.h>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <ctime>
using namespace std;
int str[5];
int a1,a2,a3,a4;
int k[5];
int main()
{
srand(time(0));
a1 = rand()%10;
a2 = rand()%10;
while(a2 == a1) a2 = rand()%10;
a3 = rand()%10;
while(a3 == a2 || a3 == a1) a3 = rand()%10;
a4 = rand()%10;
while(a4 == a2 || a4 == a1 || a4 == a3) a4 = rand()%10;
k[1] = a1, k[2] = a2, k[3] = a3, k[4] = a4;
int t = 0;
while(1)
{
int d, v = 0;
cin >> d;
while(d != 0)
{
str[++v] = d % 10;
d /= 10;
}
swap(str[1],str[4]);
swap(str[2],str[3]);
if((str[1] == k[1]) && str[2] == k[2] && str[3] == k[3] && str[4] == k[4])
{
cout << "你一共花了" << t + 1 << "次猜出.\n";
return 0;
}else{
int a = 0,b = 0;
for(int i = 1; i <= 4; i ++)
{
for(int j = 1; j <= 4; j ++)
{
if(str[i] == k[j])
{
if(i == j) a++;
else b ++;
}
}
}
cout << a << "A " << b << "B\n";
t ++;
}
}
return 0;
}