- 分享
密码破译游戏(ver. 1.0)
- @ 2025-11-16 9:16:30
符号说明: V:数字和位置都正确
O:数字正确但位置错误
X:数字错误
游戏开始前请输入游戏轮数
#include <bits/stdc++.h>
#include <set>
using namespace std;
int main()
{
int round;
cout << "Please Type In The Numbers Of Rounds.";
cin >> round ;
cout << "Start."<<"\n";
int code[4];
int arr[4];
set<int> used;
srand(time(0));
int count = 0;
while (count < 4) {
int num = rand() % 10;
if (used.find(num) == used.end()) {
arr[count] = num;
used.insert(num);
count++;
}
}
for (int i=0;i<4;i++)
{
code[i]=arr[i];
}
bool success=0;
for(int rd=0;rd<round;rd++)
{
int incode[4];
for (int i=0;i<4;i++)
{
cin>> incode[i];
}
int rightnum=0;
for (int i=0;i<4;i++)
{
bool IsExist=0;
for(int j=0;j<4;j++)
{
if(incode[i]==code[j])
{
if(i==j)
{
cout << "V ";
IsExist=1;
rightnum++;
break;
}
else
{
cout << "O ";
IsExist=1;
rightnum=0;
break;
}
}
}
if(IsExist==0)
{
cout << "X ";
rightnum=0;
}
}
if (rightnum==4)
{
success=1;
cout <<"\n"<< "Success.";
break;
}
}
if (success==0)
{
cout<<"\n" << "Failure.";
}
return 0;
}
0 comments
No comments so far...