当前位置:网站首页>Fun guessing game (not binary search! Four digits)
Fun guessing game (not binary search! Four digits)
2022-07-21 04:32:00 【Shining Sirius】
The following is the four digit guessing game code :
#include <bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <time.h>
#include <ctime>
using namespace std;
int main()
{
srand (time(0));
time_t t1;
int n1,n2,n3,n4;
int a1,a2,a3,a4;
int a,s1,s2;
cout <<" A four digit number with different digits N , It depends on how long it takes you to guess .\n\n";
cout <<" ";
system ("pause");
system ("cls");
cout <<" A four digit number with different digits N , It depends on how long it takes you to guess .\n\n";
time(&t1);
t1=t1+1;
n1=rand()%9+1;
do
n2=rand()%10;
while (n1==n2);
do
n3=rand()%10;
while (n1==n3 || n2==n3);
do
n4=rand()%10;
while (n1==n4 || n2==n3 || n3==n4);
while (1)
{
s1=0;s2=0;
cin >>a;
a1=a/1000;
a2=a/100%10;
a3=a/10%10;
a4=a%10;
if (a1==0 || a1>9)
{
cout <<" Does not meet the four digit requirement .\n\n";
Sleep(500);
continue;
}
if (a1==a2||a1==a3||a1==a4||a2==a3||a2==a4||a3==a4)
{
cout <<" It does not meet the requirements of different digits .\n\n";
Sleep(500);
continue;
}
if (a1==n1||a1==n2||a1==n3||a1==n4)
{
if (a1==n1)
{
s1++;
s2++;
}
else
s1++;
}
if (a2==n1||a2==n2||a2==n3||a2==n4)
{
if (a2==n2)
{
s1++;
s2++;
}
else
s1++;
}
if (a3==n1||a3==n2||a3==n3||a3==n4)
{
if (a3==n3)
{
s1++;
s2++;
}
else
s1++;
}
if (a4==n1||a4==n2||a4==n3||a4==n4)
{
if (a3==n3)
{
s1++;
s2++;
}
else
s1++;
}
if (s2==4)
{
cout <<" You guessed it !";
break;
}
else if (s1==0&&s2==0)
cout <<" None of the digits is right \n";
else if (s2==0)
cout <<" You're right " <<s1 <<" individual , The position is not right at all \n";
else
cout <<" You're right " <<s1 <<" individual , The position is right " <<s2 <<" individual .\n";
}
time_t t2;
time(&t2);
Sleep (50);
system ("cls");
cout <<" You use the " <<(t2-t1)/60 <<" minute " <<(t2-t1)%60 <<" second ";
return 0;
}
边栏推荐
猜你喜欢
随机推荐
BeanUtils. Copyproperties() and jsonobject What copy type is parseobject() (shallow copy or deep copy)
Shell Expect自动化交互
进程与计划任务管理中的top、pgrep、pstree、jobs、at、crontab命令
服务器托管与自建机房的对比分析
DNS域名解析服务
Comparative analysis of server hosting and self built computer rooms
编程之路,须铸金蝉之势
北京BGP机房的发展历程
Guidance process and service control
DHCP principle and configuration
什么是FTP
STM32 learning (2) GPIO
Shell脚本三种循环(多例题)
System safety and Application
Gestion des processus et des tâches prévues
DHCP principle and configuration
ARP原理
三剑客--awk
Directory and file management
expect