ÓÎÏ·¹æÔò£ºÓɼÆËã»ú¡°Ï롱һ¸öËÄλÊý£¬ÇëÈ˲ÂÕâ¸öËÄλÊýÊǶàÉÙ¡£
ÈËÊäÈëËÄλÊý×ֺ󣬼ÆËã»úÊ×ÏÈÅжÏÕâËÄλ
Êý×ÖÖÐÓм¸Î»ÊDz¶ÔÁË£¬²¢ÇÒÔÚ¶ÔµÄÊý×ÖÖÐÓÖÓм¸Î»Î»ÖÃÒ²ÊǶԵģ¬
½«½á¹ûÏÔʾ³öÀ´£¬¸øÈËÒÔÌáʾ£¬ÇëÈËÔٲ£¬Ö±µ½È˲³ö¼ÆËã»úËùÏëµÄËÄλÊýÊǶàÉÙΪֹ¡£
///////////////////////////////////////////////////²ÂÊý×ÖÓÎÏ·////////////////////////////////////////////////
#include <time.h>
//ËÄλÊý
int main()
{
int num;
int NumTable[4];
int i;
int buf[4];
int flag = 0;
srand((unsigned int)time(NULL)); /*Ëæ»úÖÖ×Ó*/
num = rand();
NumTable[3] = num % 10;
NumTable[2] = num % 100 / 10;
NumTable[1] = num % 1000 / 100;
NumTable[0] = num % 10000 / 1000;
//printf("%d\n", num);//²âÊÔÓÃ
printf("ϵͳÒѾ²úÉúËĸöËæ»úÊý×Ö\n\n");
while (1)
{
printf("ÇëÊäÈëÄã²ÂµÄËĸöÊý×Ö£º");
scanf("%d", &buf[0]);
scanf("%d", &buf[1]);
scanf("%d", &buf[2]);
scanf("%d", &buf[3]);
flag = 0;
for (i=0; i<4; i++) //Ñ»·±È½Ï4¸öÊý×Ö
{
if (buf[i] == NumTable[i]) //ÏàµÈ´òÓ¡ÂÌÉ« ×÷ΪÌáÐÑ¡£
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN);
flag++;
}
printf("%-3d", buf[i]);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
}
printf("\n");
if (flag == 4)break;
}
return 0;
}
¸´ÖÆ´úÂë