这个问题,使得人们仿佛又回到了字符界面的时代。
问题链接:。
题意简述:学生成绩有关数据的增删统计等(具体内容参见原问题)。
问题分析:使用一个结构类型数组存储数据,对其中数据进行操作。字符时代的软件似乎就是这样,只是少了用文件来存储最终的结果。
程序说明:(略)。
AC的C语言程序如下:
/* UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) */#include#include #include #define MAXN 100#define MAXLEN1 10#define MAXLEN2 20#define EPS 1e-5struct student { char sid[MAXLEN1+1]; int cid; char name[MAXLEN2+1]; int score[5]; int removed;} all[MAXN+1];int scount;void output_menu(){ printf("Welcome to Student Performance Management System (SPMS).\n\n"); printf("1 - Add\n"); printf("2 - Remove\n"); printf("3 - Query\n"); printf("4 - Show ranking\n"); printf("5 - Show Statistics\n"); printf("0 - Exit\n\n");}void add(){ int dflag, i; for(;;) { printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n"); struct student in; scanf("%s", in.sid); if(strcmp(in.sid, "0") == 0) break; scanf("%d", &in.cid); scanf("%s", in.name); scanf("%d", &in.score[1]); scanf("%d", &in.score[2]); scanf("%d", &in.score[3]); scanf("%d", &in.score[4]); dflag = 0; for(i=0; i t) high++; return high + 1;}void queryremove(int flag){ char s[MAXLEN1+1]; int i; for(;;) { printf("Please enter SID or name. Enter 0 to finish.\n"); scanf("%s", s); if(strcmp(s, "0") == 0) break; int rcount = 0; for(i=0; i = 60) count1++; else count2++; } } printf("Average Score: %.2f\n", count1+count2 == 0 ? 0 : sum*1.0/(count1+count2)+EPS); printf("Number of passed students: %d\n", count1); printf("Number of failed students: %d\n", count2); printf("\n");}void statistics(){ int id, i, j; printf("Please enter class ID, 0 for the whole statistics.\n"); scanf("%d", &id); printf("Chinese\n"); output_score(id, 1); printf("Mathematics\n"); output_score(id, 2); printf("English\n"); output_score(id, 3); printf("Programming\n"); output_score(id, 4); printf("Overall:\n"); int okcount[5]; memset(okcount, 0, sizeof(okcount)); for(i=0; i = 60) ok++; okcount[ok]++; } } printf("Number of students who passed all subjects: %d\n", okcount[4]); printf("Number of students who passed 3 or more subjects: %d\n", okcount[3]+okcount[4]); printf("Number of students who passed 2 or more subjects: %d\n", okcount[2]+okcount[3]+okcount[4]); printf("Number of students who passed 1 or more subjects: %d\n", okcount[1]+okcount[2]+okcount[3]+okcount[4]); printf("Number of students who failed all subjects: %d\n", okcount[0]); printf("\n");}int main(void){ int choice; scount = 0; for(;;) { output_menu(); scanf("%d", &choice); if(choice == 1) add(); else if(choice == 2) queryremove(0); else if(choice == 3) queryremove(1); else if(choice == 4) printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n"); else if(choice == 5) statistics(); else if(choice == 0) break; } return 0;}