#include #include #include #define WEIGHTFILE "weight.txt" #define FILENAME "data.txt" #define COUNT 10 #define HEAP_FULL(n) (n == COUNT-1) #define HEAP_EMPTY(n) (!n) typedef struct tag_HEAP{ int key; char index; }HEAP; typedef struct tag_REPORT{ char name[10]; int day; int time; char subject[4]; int progress; }REPORT; typedef struct tag_WEIGHT{ int day_weight; int time_weight; int subject_weight; int progress_weight; }WEIGHT; HEAP work[COUNT]; int index = 0; // °¡ÁßÄ¡ ºÒ·¯¿À±â void Set_weight(char *ff, WEIGHT *w); // ÀúÀåÆÄÀÏ ºÒ·¯¿À±â. void Read(char *ff, REPORT m[], int *count); // ÇöÀç °¡ÁßÄ¡ Àоî¿À±â void Display_weight(WEIGHT *w); // ÇöÀç³»¿ë Àоî¿À±â void Display(REPORT m[], int count); // °¡ÁßÄ¡ ¼öÁ¤ void Change_weight(WEIGHT *w); // ³»¿ë Ãß°¡ void Add(REPORT m[], int *count); // °¡ÁßÄ¡ ÀúÀåÇϱâ void Save_weight(char *ff, WEIGHT *w); // ³»¿ë ÀúÀå void Save(char *ff, REPORT m[], int count); // Áß¿äµµ °è»ê int Calculate(REPORT m[], WEIGHT w, int count); // ¿ì¼±¼øÀ§ ÃÖ´ëÈ÷ÇÁ¿¡ »ðÀÔ void Max_Heap_Push(HEAP w, int *n); // ¿ì¼±¼øÀ§ ÃÖ´ëÈ÷ÇÁ¿¡¼­ »èÁ¦(Ãâ·Â) HEAP Max_Heap_Pop(int *n); void main() { HEAP temp; REPORT mine[COUNT]; WEIGHT weight = {0, 0, 0, 0}; int num, i, j; int count = 0; Read(FILENAME,mine,&count); Set_weight(WEIGHTFILE,&weight); for( i = 0; i <= count; i++) { temp.key = Calculate(mine, weight, count); temp.index = count; Max_Heap_Push(temp, &index); } printf("%d",count); while(1) { system("cls"); printf("----main----\n"); printf(" 1.µî·Ï/»èÁ¦ \n"); printf(" 2.ÇÒÀÏ \n"); printf(" 3.ÀüüÃâ·Â/ÁøÇà»óȲ \n"); printf(" 4.ȯ°æ¼³Á¤\n"); printf(" 5.Á¾·á \n"); printf("¼±Åà : "); scanf("%d",&num); system("cls"); switch(num) { case 1: printf(" µî·Ï(1)/»èÁ¦(0)/³ª°¡±â \n"); printf("¼±Åà : "); scanf("%d",&num); if(num == 1){ Add(mine, &count); temp.key = Calculate(mine, weight, count); temp.index = count; Max_Heap_Push(temp, &index); printf("È®ÀÎÇϼÌÀ¸¸é ¾Æ¹«Å°³ª ´­·¯ÁÖ¼¼¿ä\n"); getche(); } else if(num == 0){ Display(mine, count); } break; case 2: printf(" 2.ÇÒÀÏ \n"); temp = Max_Heap_Pop(&index); if(temp.key == NULL) printf("°úÁ¦°¡ ¾ø½À´Ï´Ù.\n"); else{ printf("%8s %8d %8d %8s ", mine[temp.index].name, mine[temp.index].day, mine[temp.index].time, mine[temp.index].subject); printf("\n"); printf(" °úÁ¦¸¦ ÇϼÌÀ¸¸é ÁøÇà»óȲÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä, :"); scanf("%d", &mine[temp.index].progress); if( mine[temp.index].progress != 100 ) Max_Heap_Push(temp, &index); } printf("È®ÀÎÇϼÌÀ¸¸é ¾Æ¹«Å°³ª ´­·¯ÁÖ¼¼¿ä\n"); getche(); break; case 3: printf(" 3.ÀüüÃâ·Â / ÁøÇà»óȲ \n"); Display(mine, count); printf("È®ÀÎÇϼÌÀ¸¸é ¾Æ¹«Å°³ª ´­·¯ÁÖ¼¼¿ä\n"); getche(); break; case 4: printf(" 4.ȯ°æ¼³Á¤ \n"); printf(" °¡ÁßÄ¡¸¦ º¯°æÇÕ´Ï´Ù. \n\n"); printf(" ÇöÀçÀÇ °¡ÁßÄ¡ -----------\n"); Change_weight(&weight); system("cls"); printf("º¯°æµÈ °¡ÁßÄ¡\n"); Display_weight(&weight); printf("È®ÀÎÇϼÌÀ¸¸é ¾Æ¹«Å°³ª ´­·¯ÁÖ¼¼¿ä\n"); getche(); break; case 5: printf(" 5.Á¾·á \n"); printf(" º¯°æ»çÇ×À» ÀúÀåÇÕ´Ï´Ù. \n"); Save(FILENAME, mine, count); Save_weight(WEIGHTFILE, &weight); printf(" ÀúÀå¿Ï·á \n"); exit(1); break; default: printf(" ÀԷ¿À·ù ÀçÀÔ·ÂÇØÁÖ¼¼¿ä. \n\n"); getche(); break; } } } void Set_weight(char *ff,WEIGHT *w) { FILE *pf; pf = fopen(WEIGHTFILE, "rt"); fscanf(pf,"%d %d %d %d\n",&w->day_weight, &w->time_weight, &w->subject_weight, &w->progress_weight); fclose(pf); } void Read(char *file, REPORT m[], int *count) { FILE *pf; pf = fopen(FILENAME, "rt"); fscanf(pf,"%s %d %d %s %d %d", m[*count].name, &m[*count].day, &m[*count].time, m[*count].subject, &m[*count].progress); while(!feof(pf)) { (*count)++; fscanf(pf,"%s %d %d %s %d %d", m[*count].name, &m[*count].day, &m[*count].time, m[*count].subject, &m[*count].progress); } fclose(pf); } void Display_weight(WEIGHT *w) { printf("¸¶°¨±âÇÑ¿¡ ´ëÇÑ °¡ÁßÄ¡ : %d\n",w->day_weight); printf("¿¹»ó¼Ò¿ä½Ã°£¿¡ ´ëÇÑ °¡ÁßÄ¡ : %d\n",w->time_weight); printf("°ú¸ñÁß¿äµµ¿¡ ´ëÇÑ °¡ÁßÄ¡ : %d\n",w->subject_weight); printf("ÁøÇà»óȲ¿¡ ´ëÇÑ °¡ÁßÄ¡ : %d\n",w->progress_weight); } void Display(REPORT m[], int count) { int i = 0, j; printf("\n"); for(i = 0; i < count+1; i++){ printf("%8s %8d %8d %8s ", m[i].name, m[i].day, m[i].time, m[i].subject); for(j = 0; j < m[i].progress/10; j++) printf("¡Ú"); for(j = 0; j < 10-m[i].progress/10; j++) printf("¡Ù"); printf("\n"); } printf("\n"); } void Change_weight(WEIGHT *w) { int num; Display_weight(w); printf("\n"); printf("¸¶°¨±âÇÑ¿¡ ´ëÇÑ °¡ÁßÄ¡¸¦ º¯°æÇÕ´Ï´Ù :"); scanf("%d", &w->day_weight); printf("¿¹»ó¼Ò¿ä½Ã°£¿¡ ´ëÇÑ °¡ÁßÄ¡¸¦ º¯°æÇÕ´Ï´Ù :"); scanf("%d", &w->time_weight); printf("°ú¸ñÁß¿äµµ¿¡ ´ëÇÑ °¡ÁßÄ¡¸¦ º¯°æÇÕ´Ï´Ù :"); scanf("%d", &w->subject_weight); printf("ÁøÇà»óȲ¿¡ ´ëÇÑ °¡ÁßÄ¡¸¦ º¯°æÇÕ´Ï´Ù :"); scanf("%d", &w->progress_weight); } void Add(REPORT m[], int *count) { (*count)++; if(*count >= COUNT) { printf(" °úÁ¦ overflow....\n"); return; } printf(" °ú¸ñ¸í : "); scanf("%s", m[*count].name); printf(" ¸¶°¨±âÇÑ : "); scanf("%d", &m[*count].day); printf(" ¿¹»ó¼Ò¿ä½Ã°£ : "); scanf("%d", &m[*count].time); printf(" °ú¸ñÁß¿äµµ : "); scanf("%s", m[*count].subject); m[*count].progress = 0; printf("%d", *count); } void Save_weight(char *ff, WEIGHT *w) { FILE *pf; pf = fopen(ff, "wt"); fprintf(pf,"%d %d %d %d",w->day_weight, w->time_weight, w->subject_weight, w->progress_weight); fclose(pf); } void Save(char *ff, REPORT m[], int count) { FILE *pf; int i; pf = fopen(ff, "wt"); for( i = 0; i < count+1; ++i) fprintf(pf, "%10s %10d %10d %10s %10d\n", m[i].name, m[i].day, m[i].time, m[i].subject, m[i].progress); fclose(pf); } int Calculate(REPORT m[], WEIGHT w, int num) { int result; result = m[num].day * w.day_weight; result = m[num].time * w.time_weight; // result = m[num].subject * w.subject_weight; // result = m[num].progress * w.progress_weight; return result; } void Max_Heap_Push(HEAP w, int *n) { int i; if(HEAP_FULL(*n)) { printf("°úÁ¦°¡ ³Ê¹« ¸¹½À´Ï´Ù.\n"); exit(1); } i = ++(*n); while( (i != 1) && (w.key > work[i/2].key)) { work[i] = work[i/2]; i /= 2; } work[i] = w; } HEAP Max_Heap_Pop(int *n) { int parent, child; HEAP x, temp; if( HEAP_EMPTY(*n) ) { printf(" °úÁ¦°¡ ¾ø½À´Ï´Ù.\n"); return temp; } x = work[1]; temp = work[(*n)--]; parent = 1; child = 2; while(child <= *n) { if((child <= *n) && (work[child].key < work[child+1].key)) child++; if(temp.key >= work[child].key) break; work[parent] = work[child]; parent = child; child *= 2; } work[parent] = temp; return x; }