데이터 구조 과정 설계 - 운동회 점수 통계

35471 단어 데이터 구조

#include 
#include 
#include
#include 

#define Sch 10//     
#define num 10//      

typedef struct//            
{
	int AllScore; //   
	int Boyscore;//     
	int Girlscore; //     
	int School_rank;
	char NAME[20]; //      
}pro;//      

pro school[Sch];
int arr[num][5]={0};//                    

void init(int size)
{
	int i,j;
	for(i=0;i<size;i++)
	{
	   school[i].AllScore=0;
	   school[i].Boyscore=0;
	   school[i].Girlscore=0;
	   school[i].School_rank=0;
	}
} 
void  function()
{
	int i,j,d,a;
	int sumBoy[Sch]={0};//            
	int sumGirl[Sch]={0};//            
	FILE *fp;
	fp=fopen("1.txt","w");//     
	if(fp==NULL)
	{
		printf("can't open the file
"
); } else { printf("open the file successly
"
); printf(" ...
"
); } Sleep(4000); system("cls"); for(i=0;i<num;i++)// { if(i<5) { printf(" %d 5 ",i); for(j=0;j<5;j++)// { scanf("%d%d",&d,&a); //arr arr[i][j]=d; school[d].Boyscore=a; sumBoy[arr[i][j]]+=school[arr[i][j]].Boyscore; } } else { printf(" %d 3 ",i); for(j=0;j<3;j++)// { scanf("%d%d",&d,&a); //arr arr[i][j]=d; school[d].Girlscore=a; sumGirl[arr[i][j]]+=school[arr[i][j]].Girlscore; } } } for(i=0;i<Sch;i++)// { school[i].AllScore =sumBoy[i]+sumGirl[i]; } char str2[40]={"school AllScore GirlScore BoyScore"};// fprintf(fp,"%s
"
,str2); for(i=0;i<Sch;i++) { printf(" %d >>",i); scanf("%s",school[i].NAME); getchar(); fprintf(fp,"%s %d %d %d
"
,school[i].NAME,school[i].AllScore,sumGirl[i],sumBoy[i]); } fclose(fp); } void ZongFenPaiXu(int size)//size ,n , { int j=0,i; int Array[size]={0}; int cnt[size]={0};// for(i=0;i<size;i++) { Array[i]=school[i].AllScore; } while(j<size) { int max=0; for (i=0;i<size;i++) { if(school[i].AllScore>max) { max=school[i].AllScore; cnt[j]=i; } } school[cnt[j]].AllScore=0; j++; } printf("
"
); for (j=0;j<size;j++)// { printf("%d %d %d
"
,j,cnt[j],Array[cnt[j]]); school[cnt[j]].School_rank =j; } } void SearchSchool() { int School_x; printf("
"
); scanf("%d",&School_x); printf("
"
); printf("%d %d %d %d",School_x,school[School_x].AllScore,school[School_x].Boyscore,school[School_x].Girlscore); } void show_to_user() { printf("*****************************************
"
); printf("** **
"
); printf("** **
"
); printf("**1. **
"
); printf("**2. **
"
); printf("**3. **
"
); printf("*****************************************
"
); } void SearchByPro() { int i; int School_pro; printf("
"
); scanf("%d",&School_pro); if(School_pro<5) { printf("
"
); for(i=0;i<5;i++) { printf("%d\t%d
"
,i,arr[School_pro][i]); } } else { printf("
"
); for(i=0;i<3;i++) { printf("%d\t%d
"
,i,arr[School_pro][i]); } } } void menu() { int i,a; char Str[5]; while(1) { printf("
"
); scanf("%d",&i); switch(i) { case 1:ZongFenPaiXu(Sch);break; case 2:SearchSchool();break; case 3:SearchByPro();break; } printf(" yes/no
"
); scanf("%s",Str); if(!strcmp("yes",Str)) { return; } } } int main() { init(Sch);// function(); system("cls"); show_to_user(); menu(); return 0; }

좋은 웹페이지 즐겨찾기