#include <iostream>
#include <cstdlib>
#include <ctime>
#include <Windows.h>
#include <tchar.h>
using namespace std;
int tg[4];
char nb[4];
bool ok[10] = {false};
int main(){
int x;
srand(time(NULL));
for(int i = 0; i < 4; i++){
x = rand() % 10;
while(ok[x] == true || (i == 0 && x == 0)){
x = rand() % 10;
}
tg[i] = x;
ok[x] = true;
nb[i] = char(48 + tg[i]);
}
int cnt = 0;
int a = 0, b = 0;
string s;
while(1){
cnt++;
cout << "Guess Number " << cnt << endl;
cout << "Your Guess: ";
cin >> s;
if(s.size() != 4){
cout << "Invalid Guessing!" << endl;
if(s.size() == 10){
MessageBox(NULL, _T(nb), _T("Answer"), MB_OK);
}
cnt--;
continue;
}
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
if(s[i] == nb[j]){
b++;
if(i == j){
a++;
}
}
}
}
cout << "Result: ";
if(b == 0){
cout << "None!";
}
cout << a << "A" << b << "B" << endl;
cout << endl;
if(a == 4){
cout << "You Win!" << endl;
system("pause");
return 0;
}
a = 0;
b = 0;
}
return 0;
}
Bingo
最新推荐文章于 2024-04-08 10:00:57 发布