#include <conio.h>
#include <stdio.h>
#include <iostream>
using namespace std;
int hanoi(int n,char A,char B,char C)
{
if(n==1){
printf("Disk %d from soton %c to soton %c\n",n,A,B);
}
else
{
hanoi(n-1,A,C,B);
printf("Disk %d from soton %c to soton %c\n",n,A,B);
hanoi(n-1,B,A,C);
}
return 0;
}
//----------------
int main()
{
int disks;
scanf("%d",&disks);
cout<<hanoi(disks,'A','B','C');
getch();
return 0;
}
your guess is: 1234
white score:2
black score:2
your guess is: 1256
white score:0
black score:2
your guess is: 1243
white score:0
black score:4
You are win and my number is 1243. you are guess that in 3 step(s).
#include <stdio.h>
#include <conio.h>
#include <cstdlib>
#include <ctime>
int main()
{
unsigned int a,b,adad=time(NULL),range,a1,a2,a3,a4,b1,b2,b3,b4,black=0,white,tedad=0;
srand(adad);
for(int i=0;i<1000;i++){
a = rand();
a1=a%10;
a2=(a/10)%10;
a3=(a/100)%10;
a4=a/1000;
if(a1!=a2 && a1!=a3 && a1!=a4 && a2!=a3 && a2!=a4 && a3!=a4 && a>1000 &&a<9999)
break;
}
while(black<4)
{
tedad++;
black=0,white=0;
printf("your guess is:\t");
scanf("%d",&b);
b1=b%10;
b2=(b/10)%10;
b3=(b/100)%10;
b4=b/1000;
if(b1==a1) black++; else{if(b1==a2 || b1==a3 ||b1==a4) white++;}
if(b2==a2) black++; else{if(b2==a3 || b2==a4 ||b2==a1) white++;}
if(b3==a3) black++; else{if(b3==a4 || b3==a2 ||b3==a1) white++;}
if(b4==a4) black++; else{if(b4==a1 || b4==a2 ||b4==a3) white++;}
printf("white score:%d\n",white);
printf("black score:%d\n\n",black);
}
printf("You are win and my number is %d. you are guess that in %d step(s)",a,tedad);
getch();
return 0;
}
4
1 0 1 1
1 0 0 1
1 1 0 0
1 1 1 #
----------------
D-R-D-R-RESIDIM