猜数字

作者在 2008-03-10 12:43:43 发布以下内容
#include "stdlib.h"
#include "stdio.h"
#include "time.h"
int main(void)
{
int a0,b0,c0,d0;
int a1,b1,c1,d1;
int A;
int B;
int n;
char chr;
/*开始界面*/
printf("*****huan ying shi yong*****\n");
printf("*********cai shuo zi********\n");
printf("*********by:bcvg_ts*********\n");
printf("********OICQ:340194658******\n");
printf("***E-mail:bcvg_ts@163.com***\n");
/*生成随机数*/
ONE:
n=1;
randomize();
a0=random(10);
b0=random(10);
c0=random(10);
d0=random(10);
if (a0==b0||a0==c0||a0==d0) goto ONE;
if (b0==a0||b0==c0||b0==d0) goto ONE;
if (c0==a0||c0==b0||c0==d0) goto ONE;
if (d0==a0||d0==b0||d0==c0) goto ONE;
TWO:
/*输入数字,保证都不相同*/
printf("%d.INPUT NUMBER\n",n);
scanf("%1d%1d%1d%1d",&a1,&b1,&c1,&d1);
if (a1==b1||a1==c1||a1==d1)
{printf("ERROR\n");goto TWO;}
if (b1==a1||b1==c1||b1==d1)
{printf("ERROR\n");goto TWO;}
if (c1==a1||c1==b1||c1==d1)
{printf("ERROR\n");goto TWO;}
if (d1==a1||d1==b1||d1==c1)
{printf("ERROR\n");goto TWO;}
/*将输入的数字和系统生成的数字比较*/
A=0;B=0;
{
while(n<10)
{
if(a1==b0||a1==c0||a1==d0) B++ ;
if(b1==a0||b1==c0||b1==d0) B++ ;
if(c1==a0||c1==b0||c1==d0) B++ ;
if(d1==a0||d1==b0||d1==c0) B++ ;
if(a1==a0) {A++;B++;}
if(b1==b0) {A++;B++;}
if(c1==c0) {A++;B++;}
if(d1==d0) {A++;B++;}
n++ ;
/*判定输出A,B还是成功或失败*/
if(A<4)
   {
   printf("A=%d,B=%d\n",A,B);
   goto TWO;
   }
else
   {
   printf("LUCK,YOU WIN\n");
   THREE:
   printf("DO AGAIN? Y/N\n");
   scanf("%c",&chr);
   if(chr=='y') goto ONE;
   if(chr=='n') exit(0);
   }
}
printf("YOU LOSS\n");
printf("RIGHT:%1d%1d%1d%1d\n",a0,b0,c0,d0);
goto THREE;
}
}
默认分类 | 阅读 1793 次
文章评论,共0条
游客请输入验证码
浏览35730次
文章分类