UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) 代码
#include <bits/stdc++.h>
#define int long long
#define judge(a,func) case a:func();break;
using namespace std;
void println(string s){
cout<<s<<'\n';
}
void main_menu(){
println("Welcome to Student Performance Management System (SPMS).");
println("");
println("1 - Add");
println("2 - Remove");
println("3 - Query");
println("4 - Show ranking");
println("5 - Show Statistics");
println("0 - Exit");
println("");
}
struct Student{
string sid,name;
int cid;
int chinese,mathematics,english,programming;
bool operator==(const Student &x) const{
return sid==x.sid && cid==x.cid && chinese==x.chinese && mathematics==x.mathematics && english==x.english && programming == x.programming;
}
};
vector<Student> v;
map<string,bool> duplicated;
void add(){
println("Please enter the SID, CID, name and four scores. Enter 0 to finish.");
string sid;
cin>>sid;
if(sid=="0")return;
Student student;
student.sid=sid;
cin>>student.cid>>student.name>>student.chinese>>student.mathematics>>student.english>>student.programming;
if(duplicated[sid]){
println("Duplicated SID.");
}
else{
duplicated[sid]=1;
v.push_back(student);
}
add();
}
void remove(){
println("Please enter SID or name. Enter 0 to finish.");
string str;
cin>>str;
stack<vector<Student>::iterator> removing;
if(str=="0")return;
int tot=0;
for(auto ite=v.begin();ite!=v.end();ite++){
if((*ite).sid==str || (*ite).name==str){
tot++;
duplicated[(*ite).sid]=0;
removing.push(ite);
}
}
while(!removing.empty()){
v.erase(removing.top());
removing.pop();
}
cout<<tot;
println(" student(s) removed.");
remove();
}
int total(Student x){
return x.chinese+x.english+x.mathematics+x.programming;
}
void query(){
println("Please enter SID or name. Enter 0 to finish.");
string str;
cin>>str;
if(str=="0")return;
for(Student i : v){
if(i.sid==str || i.name==str){
vector<Student> same_class;
for(Student j : v){
same_class.push_back(j);
}
sort(same_class.begin(),same_class.end(),[&](const Student &x,const Student &y){
return x.chinese+x.mathematics+x.english+x.programming>y.chinese+y.mathematics+y.english+y.programming;
});
int ret=0;
for(vector<Student>::size_type j=0;j<same_class.size();j++){
if(j>0&&total(same_class[j])==total(same_class[j-1])){}
else ret=j+1;
if(same_class[j]==i){
break;
}
}
cout<<ret<<' '<<i.sid<<' '<<i.cid<<' '<<i.name<<' ';
cout<<i.chinese<<' '<<i.mathematics<<' '<<i.english<<' '<<i.programming<<' ';
cout<<(i.chinese+i.mathematics+i.english+i.programming)<<' ';
printf("%.2lf\n",((double)((i.chinese+i.mathematics+i.english+i.programming))/4.0)+1e-5);
}
}
query();
}
void show_ranking(){
println("Showing the ranklist hurts students' self-esteem. Don't do that.");
}
void show_statisitics(){
println("Please enter class ID, 0 for the whole statistics.");
int cid;cin>>cid;
int passed=0,failed=0;
double aver=0;
int cnt=0;
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
cnt++;
}
{
println("Chinese");
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
aver += i.chinese;
passed += (i.chinese >= 60);
failed += (i.chinese < 60);
}
aver /= cnt;
cout<<"Average Score: ";
printf("%.2lf\n",aver+1e-5);
cout<<"Number of passed students: "<<passed<<'\n';
cout<<"Number of failed students: "<<failed<<'\n';
println("");
}
{
aver=0;failed=0;passed=0;
println("Mathematics");
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
aver += i.mathematics;
passed += (i.mathematics >= 60);
failed += (i.mathematics < 60);
}
aver /= cnt;
cout<<"Average Score: ";
printf("%.2lf\n",aver+1e-5);
cout<<"Number of passed students: "<<passed<<'\n';
cout<<"Number of failed students: "<<failed<<'\n';
println("");
}
{
aver=0;failed=0;passed=0;
println("English");
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
aver += i.english;
passed += (i.english >= 60);
failed += (i.english < 60);
}
aver /= cnt;
cout<<"Average Score: ";
printf("%.2lf\n",aver+1e-5);
cout<<"Number of passed students: "<<passed<<'\n';
cout<<"Number of failed students: "<<failed<<'\n';
println("");
}
{
aver=0;failed=0;passed=0;
println("Programming");
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
aver += i.programming;
passed += (i.programming >= 60);
failed += (i.programming < 60);
}
aver /= cnt;
cout<<"Average Score: ";
printf("%.2lf\n",aver+1e-5);
cout<<"Number of passed students: "<<passed<<'\n';
cout<<"Number of failed students: "<<failed<<'\n';
println("");
}
println("Overall:");
int all=0,one=0,two=0,three=0,failed_all=0;
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
int ret = (int)(i.chinese>=60)+(int)(i.mathematics>=60)+(int)(i.english>=60)+(int)(i.programming>=60);
if(ret>=1)one++;
if(ret>=2)two++;
if(ret>=3)three++;
if(ret>=4)all++;
if(ret==0)failed_all++;
}
cout<<"Number of students who passed all subjects: "<<all<<'\n';
cout<<"Number of students who passed 3 or more subjects: "<<three<<'\n';
cout<<"Number of students who passed 2 or more subjects: "<<two<<'\n';
cout<<"Number of students who passed 1 or more subjects: "<<one<<'\n';
cout<<"Number of students who failed all subjects: "<<failed_all<<'\n';
println("");
}
signed main(){
// freopen("1.out","w",stdout);
while(1){
main_menu();
int op;
cin>>op;
switch(op){
judge(1,add);
judge(2,remove);
judge(3,query);
judge(4,show_ranking);
judge(5,show_statisitics);
case 0:return 0;
}
}
}
UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) 代码的更多相关文章
- 【例题4-6 uva12412】A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 训练编程的题. 原题中没有除0的数据,所以别担心你的代码是因为除0错了. 多半跟我一样. 也是因为没有+eps 就是比如你要算tot ...
- UVA12412 师兄帮帮忙 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) 题解
Content 自己去看题面去. Solution 算不上很繁琐的一道大模拟. 首先,既然是输出 \(0\) 才退出,那么在此之前程序应当会执行菜单 \(\Rightarrow\) 子操作 \(\Ri ...
- UVA 12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)
题目链接:https://vjudge.net/problem/UVA-12412 题目大意 略. 分析 比较大规模的模拟,注意输入输出,浮点数精度,还有排名相同的输出顺序,还有一些边界情况处理. 代 ...
- A Typical Homework(学生信息管理系统)
A Typical Homework(a.k.a Shi Xiong Bang Bang Mang) Hi, I am an undergraduate student in institute of ...
- 《K&R》里贯穿全书的代码
个人阅读<K&R>的感觉就是:前后内容联系特别紧密,前面的代码没有理解好到了后面就看不下去. 1.getline(char s[], int lim) 调用结果:往参数数组中读入字 ...
- k.tt 研究下生成的逻辑代码:从壹开始前后端分离 [.netCore 填坑 ] 三十二║ 四种方法快速实现项目的半自动化搭建
更新 1.更新小伙伴 @大龄Giser 提出好点子:试试VS的插件扩展:VSIX.ItemProject等,将T4模板给制作插件,这里先记下,有懂的小伙伴可以自己先试试,我会在以后更新. 2.感谢小伙 ...
- k/3cloud表格控件块粘贴代码逻辑
大家可以在表单插件EntityBlockPasting事件中自己处理,然后将cancel设置为true.以下代码可以参考一下,插件代码中需要将其中一些属性或方法修改,例如this.BusinessIn ...
- [LeetCode] Top K Frequent Elements 前K个高频元素
Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...
- 71. Merge k Sorted Lists
Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and descr ...
- 【编程题目】查找最小的 k 个元素
5.查找最小的 k 个元素(数组)题目:输入 n 个整数,输出其中最小的 k 个.例如输入 1,2,3,4,5,6,7 和 8 这 8 个数字,则最小的 4 个数字为 1,2,3 和 4. 算法里面学 ...
随机推荐
- 在电脑主机(MainFrame)中只需要按下主机的开机按钮(on()),即可调用其它硬件设备和软件的启动方法,如内存(Memory)的自检(check())、CPU的运行(run())、硬盘(Hard
欢迎大家加入我的社区:http://t.csdn.cn/Q52km 社区中不定时发红包 文章目录 1.UML类图 2.源码 3.优缺点 1.UML类图 2.源码 package com.zheng; ...
- python信息检索实验之向量空间模型与布尔检索
import numpy as np import pandas as pd import math def bool_retrieval(string): if string.count('and' ...
- Elasticsearch rest-high-level-client 基本操作
Elasticsearch rest-high-level-client 基本操作 本篇主要讲解一下 rest-high-level-client 去操作 Elasticsearch , 虽然这个客户 ...
- Byte和byte的区别
Byte和byte的区别 背景 今天学习网络编程中,在建立Udp连接时,使用byte[]数组接收传输的数据,但是byte[]错写为Byte[],导致错误. //接收数据: Byt ...
- 第一百零七篇:基本数据类型(undefined,null,boolean类型)
好家伙, 本篇内容为<JS高级程序设计>第三章学习笔记 1.数据类型 ECMAScript有6种简单数据类型(称为原始类型): Undefined, Null, Boolean, Numb ...
- 3. qtdesinger的使用方法
专栏地址 ʅ(‾◡◝)ʃ windows 上使用 qtdesigner 找到那个路径直接打开就行了 linux 上使用 qtdesigner 打开 qtcreator 软件 1. 启动软件,新建项目 ...
- 在Cloudreve网盘系统中集成kkFileView在线预览(暂时)
服务器:WindowsServer 2016 Cloudreve 需求方想整一个在小团队内部使用的网盘系统,最终在千挑万选之下选中了Cloudreve. Github地址:https://github ...
- 《MySQL必知必会》知识汇总一
一.使用MYSQL 展示所有数据库 show databases; 选择数据库 use crashcourse; 展示该数据库中所有的表 show tables; 还可以展示表列的shema约束 sh ...
- 深刻理解JAVA并发中的有序性问题和解决之道
欢迎关注专栏[JAVA并发] 更多技术干活尽在个人公众号--JAVA旭阳 问题 Java并发情况下总是会遇到各种意向不到的问题,比如下面的代码: int num = 0; boolean ready ...
- 基于pyecharts的中医药知识图谱可视化
基于pyecharts的中医药知识图谱可视化 关键词: pyecharts:可视化:中医药知识图谱 摘要: 数据可视化是一种直观展示数据结果和变化情况的方法,可视化有助于知识发现与应用.Neo4j数据 ...