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

问题链接:UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)。

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

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

程序说明:(略)。

AC的C语言程序如下:

/* UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) */#include <stdio.h>
#include <string.h>
#include <memory.h>#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<scount; i++)if(!all[i].removed && strcmp(in.sid, all[i].sid)==0) {printf("Duplicated SID.\n");dflag = 1;continue;}if(!dflag) {in.score[0] = in.score[1] + in.score[2] + in.score[3] + in.score[4];in.removed = 0;all[scount++] = in;}}
}int rank(int x)
{int t = all[x].score[0];int high=0, i;for(i=0; i<scount; i++)if(!all[i].removed && all[i].score[0] > 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<scount; i++) {if(!all[i].removed && (strcmp(s, all[i].sid) == 0 || strcmp(s, all[i].name) == 0)) {if(flag){printf("%d %s %d %s %d %d %d %d %d %.2f\n", rank(i), all[i].sid, all[i].cid, all[i].name,all[i].score[1], all[i].score[2], all[i].score[3], all[i].score[4], all[i].score[0], all[i].score[0]/4.0+EPS);}else{all[i].removed = 1;rcount++;}}}if(!flag)printf("%d student(s) removed.\n", rcount);}
}void output_score(int id, int type)
{int sum=0, count1=0, count2=0, i;for(i=0; i<scount; i++) {if(!all[i].removed && (id == 0 || all[i].cid == id)) {sum += all[i].score[type];if(all[i].score[type] >= 60)count1++;elsecount2++;}}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<scount; i++) {if(!all[i].removed && (id == 0 || all[i].cid == id)) {int ok = 0;for(j=1; j<=4; j++)if(all[i].score[j] >= 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

UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)相关推荐

  1. UVa12412 - A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

    wrong answer很奇怪.经过几天找测试例子,终于找到原因了.在计算Overall时,计数有问题,原来用的是位操作,值>1将pass1加1,>=3将pass2加1,这种计算方式不对. ...

  2. UVA - 12412 ​​​​​​​A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

    A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) UVA - 12412 题目传送门 emmmm,不想表达什么,udbug上的数据全过,可就是WA ...

  3. A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) UVA - 12412

    题目链接:A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) UVA - 12412 思路:自顶而上,先写出框架,再写具体函数. 框架: int m ...

  4. UVa 12412 - A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

    是道例题,编写个管理系统,类似于课本十二章的那个.自己写的代码运行样例正常,但提交WA.而且给了一半的代码,就又上网搜了例题原版代码.对比了输入与输出,一直没找到错,目测是有个地方格式错了或者精度控制 ...

  5. UVA - 12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

    题目来源:https://cn.vjudge.net/problem/UVA-12412//题目太长不想复制 题意: 写一个学生成绩管理系统 (SPMS). SID:10位数字 CID:不超过20的整 ...

  6. UVA12412 A Typical Homework (a.k.a 师兄帮帮忙) 题解

    题意 实现一个学生信息管理系统,完成要求功能,并按要求输出.具体内容可以看[UVA12412](UVA12412 A Typical Homework (a.k.a 师兄帮帮忙) - 洛谷 | 计算机 ...

  7. UVA12412 A Typical Homework (a.k.a 师兄帮帮忙)

    这是一道模拟题,不能提升算法能力,但是能大大提升编程能力,这道题主要就是编写五个函数,一个一个说, 首先是第一个添加函数,这个函数需要注意的是,学生id是不能重复的,也就是这个学生id已经出现过了那么 ...

  8. Uva12412 a.k.a Shi Xiong Bang Bang Mang

    这题综合性挺强的,刷题的时候debug改了两天.坑:每次query重新排序.求大佬轻喷. 原题: ac代码(还有很多地方能优化,能让代码变得更简短,不过我懒得去看了(- ̄▽ ̄)-) #include& ...

  9. 师兄帮帮忙(A Typical Homework,ACM)

    #include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...

最新文章

  1. 技术贴 | MetaboAnalyst 4.0,代谢组学研究利器的升级
  2. 引起Java序列化失败的常见原因
  3. CF1016F:Road Projects(树形dp)
  4. ubtunu打开firefox_Linux Ubuntu 终端命令行打开firefox报错
  5. 近日的思绪(外三首)
  6. 【今日CV 计算机视觉论文速览】19 Mar 2019
  7. leetcode - 1155. 掷骰子的N种方法
  8. codeforces 892E(离散化+可撤销并查集)
  9. 最便宜的骁龙888旗舰机!realme真我GT正式发布:2799元起售
  10. 解决Keras 与 Tensorflow 版本之间的兼容性问题,导入keras报错:module 'tensorflow.python.keras.backend' has no attribute
  11. https 加端口_Ubuntu 安装Node 10.16 跑 Nodeppt 加Hexo博客再来个为知笔记私有云
  12. C-Free注册码,密钥,到期解决办法
  13. 详解数据库锁机制和原理
  14. 国科大.模式识别与机器学习.期末复习笔记手稿+复习大纲
  15. format mla_MLAFormatMLA格式解读
  16. linux下拷贝某一时间段的文件
  17. java毕业设计总结
  18. windows 增加开机启动服务器,Windows Server2012删除或添加开机启动项的方法
  19. S3C2440系统中断(转)
  20. 圆角装饰条_护角条是圆角好还是直角好

热门文章

  1. python install pip 区别_python conda、pip区别,python 下 faiss 安装
  2. unittest所有断言方法
  3. Keil C51的库函数
  4. 关于监听UITextField的问题
  5. 提取验证码到winform上webbroswer和axwebbroswer
  6. 终于等到DUDU把MetaBlog Api打开了
  7. ESP8266代码分析
  8. 不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况
  9. Linux大文件格式,linux – 用于打印大文件的命令,按大小以人类可读的格式排序...
  10. 大数据翻页_【干货】大数据翻页的难点和技巧