📄 twelf.c
字号:
#include "time.h"
#include "math.h"
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
void judge(void)
{
int a[12],i,j,k,weight,pos;
clrscr();
j=random(2);
j=j*2;
k=random(12);
for(i=0;i<12;i++)
{
if (i==k)
{
a[i]=j;
textcolor(RED);
}
else
{
a[i]=1;
textcolor(LIGHTGRAY);
}
cprintf("a[%d]is : %d \n\r",i,a[i]);
}
//to make an aray in which there is a bigger or smaller element
// than any other one,and this one is possible in any position
////////////////////////////////////////////////////////////////////
//to judeg which one is bigger or smaller
weight=0;pos=0;
if((a[0]+a[1]+a[2]+a[3])==(a[4]+a[5]+a[6]+a[7]))
{
if((a[0]+a[1]+a[2])==(a[8]+a[9]+a[10]))
{
pos=11;
if(a[0]>a[11])
weight=0; //a[11] smaller
else
weight=2; //a[11] bigger
}
else if((a[0]+a[1]+a[2])>(a[8]+a[9]+a[10]))
{
weight=0;
if(a[8]==a[9])
pos=10; //a[10] smaller
else if(a[8]>a[9])
pos=9; //a[9] smaller
else
pos=8; //a[8] smaller
}
else
{
weight=2;
if(a[8]==a[9])
pos=10; //a[10] bigger
else if(a[8]>a[9])
pos=8; //a[8] bigger
else
pos=9; //a[9] bigger
}
}
else if((a[0]+a[1]+a[2]+a[3])>(a[4]+a[5]+a[6]+a[7]))
{
if((a[0]+a[1]+a[7])>(a[2]+a[3]+a[4]))
{
if(a[0]==a[1])
{
weight=0;
pos=4; //a[4] smaller
}
else if(a[0]>a[1])
{
weight=2;
pos=0; //a[0] bigger
}
else
{
weight=2;
pos=1; //a[1] bigger
}
}
else if((a[0]+a[1]+a[7])<(a[2]+a[3]+a[4]))
{
if(a[2]==a[3])
{
weight=0;
pos=7; //a[7] smaller
}
else if(a[2]>a[3])
{
weight=2;
pos=2; //a[2] bigger
}
else
{
weight=2;
pos=3; //a[3] bigger
}
}
else
{
weight=0;
if(a[5]>a[6])
pos=6; //a[6] smaller
else pos=5; //a[5] smaller
}
}
else
{
if((a[4]+a[5]+a[3])>(a[6]+a[7]+a[0]))
{
if(a[4]==a[5])
{
weight=0;
pos=0; //a[0] smaller
}
else if(a[4]>a[5])
{
weight=2;
pos=4; //a[4] bigger
}
else
{
weight=2;
pos=5; //a[5] bigger
}
}
else if((a[4]+a[5]+a[3])<(a[6]+a[7]+a[0]))
{
if(a[6]==a[7])
{
weight=0;
pos=3; //a[3] smaller
}
else if(a[6]>a[7])
{
weight=2;
pos=6; //a[6] bigger
}
else
{
weight=2;
pos=7; //a[7] bigger
}
}
else
{
weight=0;
if(a[1]>a[2])
pos=2; //a[2] smaller
else pos=1; //a[1] smaller
}
}
///////////////////////////////////////////////////////////////////
//to judge which one is bigger or smaller
textcolor(LIGHTGRAY);
cprintf("The different one is ");
textcolor(CYAN);
cprintf("a[%d]",pos);
textcolor(LIGHTGRAY);
cprintf(",and it's ");
textcolor(MAGENTA);
if(weight==0)
{
cprintf("smaller ");
}
else
{
cprintf("bigger ");
}
textcolor(LIGHTGRAY);
cprintf("than others\n\r\n\r");
}
void main()
{
char m;
clrscr();
randomize();
for(;m!='n'&&m!='N';)
{
judge();
printf("Press 'N' to exit and others to run another time\n\n");
m=getch();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -