博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)
阅读量:6599 次
发布时间:2019-06-24

本文共 3201 字,大约阅读时间需要 10 分钟。

这个问题,使得人们仿佛又回到了字符界面的时代。

问题链接:。

题意简述:学生成绩有关数据的增删统计等(具体内容参见原问题)。

问题分析:使用一个结构类型数组存储数据,对其中数据进行操作。字符时代的软件似乎就是这样,只是少了用文件来存储最终的结果。

程序说明(略)。

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;}

转载于:https://www.cnblogs.com/tigerisland/p/7564305.html

你可能感兴趣的文章
VScode运行
查看>>
GIEC2019第六届全球互联网经济大会北京站震撼来袭!
查看>>
DAMS2019中国数据智能管理峰会将于7月在上海召开!
查看>>
一题多解【发散思维拓展训练】
查看>>
SDN第四次作业
查看>>
Spark:使用Java代码提交spark任务
查看>>
P4718 【模板】Pollard-Rho算法
查看>>
AtCoder Grand Contest 033 题解
查看>>
显示GridControl的横向滚动条
查看>>
poj 1125 Stockbroker Grapevine
查看>>
BZOJ3238 [Ahoi2013]差异
查看>>
在.NET中使用highcharts实例代码
查看>>
052_Lightning
查看>>
高德地图 使用案例
查看>>
浅拷贝和深拷贝
查看>>
自动化测试===Macaca环境搭建,自我总结
查看>>
PHP文件上传处理
查看>>
java。接口
查看>>
JavaScript面试技巧(三):开发环境、运行环境
查看>>
flex与几种页面间的交互方式
查看>>