源代码是这个
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
#include<dos.h>
#include <windows.h>
void gotoxy(int x, int y) //x为列坐标,y为行坐标
{
COORD pos = {x,y}; //设定坐标
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); //函数句柄
SetConsoleCursorPosition(hOut, pos);
}
void guess(int n)
{
int acount,bcount,i,j,k=0,flag;
int a[10],b[10],f[10]={0};
int x=0;
srand((unsigned)time(NULL));
while(x<n)
{
int m=rand()%10;
if(f[m]==1)
continue;
a[x++]=m;
f[m]=1;
}
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
logo:printf("guess:\n");
k++;
acount=0;
bcount=0;
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(a[i]==b[i])
{
acount++;
break;
}
if(a[i]=b[j]&&i!=j)
{
bcount++;
break;
}
}
printf("clue on:%d A %d B\n\n",acount,bcount);
if(acount<n)
goto logo;
else
if(acount==n)
{
if(k==1)
printf("you are a!!\n\n");
else if(k<=5)
printf("you are b!!\n\n");
else if(k<=10)
printf("you are c!!\n\n");
else
printf("you are fool!!\n\n");
}
}
void main()
{
int i,n;
while(1)
{
system("cls");
gotoxy(15,6);
printf("1 start ganme?(y/n)");
gotoxy(15,8);
printf("2 rule");
gotoxy(15,10);
printf("3 exit\n");
gotoxy(25,15);
printf("please choose:");
scanf("%d",&i);
switch(i)
{
case 1: system("cls");
printf("plesae input n:\n");
scanf("%d",&n);
guess(n);
Sleep(100000);
break;
case 2: system("cls");
printf("\t\tthe rule of game\n");
printf("step1:input number of digits\n");
printf("step2:input the number,separated by a space between two numbers\n");
printf("step3:a represent location and data are correct\n");
printf("\tb represent location is correct but data is wrong\n");
Sleep(10000);
break;
default: break;
}
}
getchar();
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
#include<dos.h>
#include <windows.h>
void gotoxy(int x, int y) //x为列坐标,y为行坐标
{
COORD pos = {x,y}; //设定坐标
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); //函数句柄
SetConsoleCursorPosition(hOut, pos);
}
void guess(int n)
{
int acount,bcount,i,j,k=0,flag;
int a[10],b[10],f[10]={0};
int x=0;
srand((unsigned)time(NULL));
while(x<n)
{
int m=rand()%10;
if(f[m]==1)
continue;
a[x++]=m;
f[m]=1;
}
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
logo:printf("guess:\n");
k++;
acount=0;
bcount=0;
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(a[i]==b[i])
{
acount++;
break;
}
if(a[i]=b[j]&&i!=j)
{
bcount++;
break;
}
}
printf("clue on:%d A %d B\n\n",acount,bcount);
if(acount<n)
goto logo;
else
if(acount==n)
{
if(k==1)
printf("you are a!!\n\n");
else if(k<=5)
printf("you are b!!\n\n");
else if(k<=10)
printf("you are c!!\n\n");
else
printf("you are fool!!\n\n");
}
}
void main()
{
int i,n;
while(1)
{
system("cls");
gotoxy(15,6);
printf("1 start ganme?(y/n)");
gotoxy(15,8);
printf("2 rule");
gotoxy(15,10);
printf("3 exit\n");
gotoxy(25,15);
printf("please choose:");
scanf("%d",&i);
switch(i)
{
case 1: system("cls");
printf("plesae input n:\n");
scanf("%d",&n);
guess(n);
Sleep(100000);
break;
case 2: system("cls");
printf("\t\tthe rule of game\n");
printf("step1:input number of digits\n");
printf("step2:input the number,separated by a space between two numbers\n");
printf("step3:a represent location and data are correct\n");
printf("\tb represent location is correct but data is wrong\n");
Sleep(10000);
break;
default: break;
}
}
getchar();
}