#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 3
int main()
{
int sim();
int mix();
struct Team
{
char name;
int score;
}
team[N];
struct Team temp;
int i,j,p,t,k,n,m;
int result1,answer1,result2,answer2;
char ch1,ch2;
printf("
*********************************\n");
printf("
*
*\n");
printf("
*
*\n");
printf("
*welcome join in this competiton*\n");
printf("
*
*\n");
printf("
*
*\n");
printf("
*********************************\n");
for(i=0,j=65;i<N;i++,j++)
{
team[i].name = j;
team[i].score = 100;
}
printf("\n\n\n\n");
printf("input simple count number n:");
scanf("%d",&n);
printf("input mix count number m:");
scanf("%d",&m);
printf("\n");
system("pause");
printf("The first turen.\n");
printf("This is simple count.\n");
printf("Please look at the question:");
for(p=0;p<n;p++)
{
result1=sim();
printf("Please input one team name(A,B,C...):");
getchar();
scanf("%c",&ch1);
printf("\ninput your answer:");
scanf("%d",&answer1);
for(k=0;k<N;k++)
{
t=k;
if(ch1 == team[k].name)
if(result1 == answer1)
{
printf("The answer is right.\n");
team[t].score +=5;
}
else
{
printf("This answer is wrong.\n");
printf("The right answer is %d\n\n",result1);
team[t].score -=5;
}
}
for(i=0;i<N;i++)
{
printf("************\n");
printf("*%c
%4d*\n",team[i].name,team[i].score);
printf("***********\n");
}
printf("\n");
}
printf("The first turn is end.\n\n\n\n\n");
printf("The second turn begain!\n");
printf("This is mix count!\n");
printf("Please look at the question:\n");
for(p=0;p<m;p++)
{
result2 =mix();
printf("please input one team(A,B,C...):");
getchar();
scanf("%c",&ch2);
printf("\ninput your answer.");
scanf("%d",&answer2);
for(k=0;k<N;k++)
{
t=k;
if(ch2 == team[k].name)
if(result2 == answer2)
{
printf("The answer is right.\n");
team[k].score +=10;
}
else
{
printf("\nyour answer is wrong.\n");
printf("The right answer is %d\n",result2);
team[k].score -=10;
}
}
for(i=0;i<N;i++)
{
printf("*********\n");
printf("*%c%4d*",team[i].name,team[i].score);
printf("*********\n");
}
printf("\n");
}
printf("The second turn is end.\n\n");
printf("\nThe last result:\n");
for(i=0;i<N-1;i++)
for(j=0;j<N-1;j++)
if(team[j].score < team[j+1].score)
{
temp = team[j];
team[j] = team[j+1];
team[j+1]=temp;
}
for(i=0;i<N;i++)
{
printf("*******\n");
printf("%c%4d*",team[i].name,team[i].score);
printf("******\n");
}
printf("\n\n\n\n");
printf("
******************************\n");
printf("
*
*\n");
printf("
*
*\n");
printf("
*
Thanks for using!
*\n");
printf("
*
*\n");
printf("
*
*\n");
printf("
******************************\n");
return 0;
}
int sim()
{
int s,num1,num2,stpy;
srand((unsigned)time(NULL));
num1= rand()%10;
num2 = rand()%10;
stpy= rand()%4+1;
switch(stpy)
{
case 1:
s=num1+num2;
printf("%d+%d=?\n",num1,num2);
break;
case 2:
if(num1>=num2)
{
s=num1-num2;
printf("%d-%d=?\n",num1,num2);
break;
}
else
{
s=num2-num1;
printf("%d-%d=?\n",num2,num1);
break;
}
case 3:
s=num1*num2;
printf("%d*%d=?\n",num2,num1);
break;
case 4:
s=num1/num2;
printf("%d/%d=?(仅取商)\n",num2,num1);
break;
}
return(s);
}
int mix()
{
int t,num1,num2,num3,num4,stpy;
srand((unsigned)time(NULL));
num1= rand()%10;
num2 = rand()%10;
num3= rand()%10;
num4 = rand()%10;
switch(stpy)
{
case 1:
t=(num1+num2)*(num3+num4);
printf("(%d+%d)*(%d+%d)=?\n",num1,num2,num3,num4);
break;
case 2:
if(num1>=num2)
{
t=(num1-num2)*(num3+num4);
printf("(%d-%d)*(%d+%d)=?\n",num1,num2,num3,num4);
break;
}
else
{
t=(num2-num1)*(num3+num4);
printf("(%d-%d)*(%d+%d)=?\n",num1,num2,num3,num4);
break;
}
case 3:
t=num1*num2-num3*num4;
printf("%d*%d-%d*%d=?\n",num1,num2,num3,num4);
break;
case 4:
t=(num1+num2-num3)*num4;
printf("(%d+%d-%d)*%d=?\n",num1,num2,num3,num4);
break;
}
return(t);
}