【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

训练编程的题。
原题中没有除0的数据,所以别担心你的代码是因为除0错了。
多半跟我一样。
也是因为没有+eps
就是比如你要算tot/4的值。
那么要输出tot/4+1e-6
不然会错。。。
浮点误差...

剩下的。其实很简答的。。

注意有并列第x的情况就好。

【代码】

#include <bits/stdc++.h>
using namespace std; const string subject[4]={"Chinese","Mathematics","English","Programming"}; struct abc{
string sid,cid,name;
int goal[4];int tot;
}; int ope;
vector<abc> v;
vector<abc> temp;
map<string,int> ranking; void output_message(){
cout<<"Welcome to Student Performance Management System (SPMS)."<<endl<<endl;
cout<<"1 - Add"<<endl;
cout<<"2 - Remove"<<endl;
cout<<"3 - Query"<<endl;
cout<<"4 - Show ranking"<<endl;
cout<<"5 - Show Statistics"<<endl;
cout<<"0 - Exit"<<endl<<endl;
} void tip(int idx){
if (idx==1) cout<<"Please enter the SID, CID, name and four scores. Enter 0 to finish."<<endl;
if (idx==2) cout<<"Please enter SID or name. Enter 0 to finish."<<endl;
if (idx==3) cout<<"Please enter SID or name. Enter 0 to finish."<<endl;
if (idx==4) cout<<"Showing the ranklist hurts students' self-esteem. Don't do that."<<endl;
if (idx==5) cout<<"Please enter class ID, 0 for the whole statistics."<<endl;
} bool found_student_by_sid(string sid){
for (abc temp:v) if (temp.sid==sid) return true;
return false;
} int _remove(string par,int p){
int cnt = 0;
vector<abc> newv;newv.clear();
for (int i = 0;i < (int) v.size();i++){
if ( (p==0 && v[i].sid == par) || (p==1 && v[i].name == par) ){
cnt++;
}else newv.push_back(v[i]);
}
v.resize((int)newv.size());
v = newv;
return cnt;
} bool cmp(abc a,abc b){
return a.tot>b.tot;
} int main(){
//freopen("/home/ccy/rush.txt","r",stdin);
//freopen("/home/ccy/rush_out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0);
while (1){
output_message();
cin >> ope;
if (ope==1){
while(1){
tip(1);
abc temp;
cin >> temp.sid;
if (temp.sid=="0") break;
temp.tot = 0;
cin >> temp.cid >> temp.name;
for (int i = 0;i < 4;i++){
cin >> temp.goal[i];
temp.tot+=temp.goal[i];
}
if (found_student_by_sid(temp.sid))
cout<<"Duplicated SID."<<endl;
else
v.push_back(temp);
}
}
if (ope==2){
while (1){
tip(2);
string s;
cin >> s;
if (s=="0") break;
int p = 0;
if (s[0]>='A' && s[0]<='Z') p = 1;
cout<<_remove(s,p)<<" student(s) removed."<<endl;
}
}
if (ope==3){
while (1){
tip(3);
string s;
cin >> s;
if (s=="0") break;
temp.resize((int)v.size());
for (int i = 0;i < (int)v.size();i++) temp[i] = v[i];
sort(temp.begin(),temp.end(),cmp);
for (int i = 0;i < (int)v.size();i++){
int cur = i+1,j = i;
ranking[temp[i].sid] = cur;
while (j+1<(int)v.size() && temp[j+1].tot==temp[i].tot) {
j++;
ranking[temp[j].sid] = cur;
}
i = j;
}
int p = 0;
if (s[0]>='A' && s[0]<='z') p = 1;
for (int i = 0;i < (int)v.size();i++){
if ( (p==0 && v[i].sid == s) || (p==1 && v[i].name==s) ){
cout<<ranking[v[i].sid]<<" ";
cout<<v[i].sid<<" "<<v[i].cid<<" "<<v[i].name<<" ";
for (int j = 0;j < 4;j++) cout<<v[i].goal[j]<<" ";
cout<<v[i].tot<<" ";
cout<<fixed<<setprecision(2)<<1.0*v[i].tot/4.0+(1e-5)<<endl;
}
}
}
}
if (ope==4) tip(4);
if (ope==5){
tip(5);
string s;
cin >> s;
for (int i = 0;i < 4;i++){
int cntb60 = 0,cntl60 = 0,tot =0,cnt = 0;
for (int j = 0;j < (int)v.size();j++){
if (v[j].cid==s || s=="0"){
if (v[j].goal[i]>=60){
cntb60++;
}else cntl60++;
tot+=v[j].goal[i];
cnt++;
}
}
cout<<subject[i]<<endl;
cout<<"Average Score: ";
cout<<fixed<<setprecision(2)<<1.0*tot/(1.0*cnt)+(1e-5)<<endl; cout<<"Number of passed students: "<<cntb60<<endl;
cout<<"Number of failed students: "<<cntl60<<endl;
cout<<endl;
}
cout<<"Overall:"<<endl;
int cnt[5]={0};
for (int i = 0;i < (int)v.size();i++)
if (v[i].cid==s || s=="0"){
int temp = 0;
for (int j = 0;j < 4;j++){
if (v[i].goal[j]>=60) temp++;
}
cnt[temp]++;
}
cout<<"Number of students who passed all subjects: "<<cnt[4]<<endl;
for (int i = 3;i >= 1;i--) cnt[i]+=cnt[i+1];
for (int i = 3;i >= 1;i--)
cout<<"Number of students who passed "<<i<<" or more subjects: "<<cnt[i]<<endl;
cout<<"Number of students who failed all subjects: "<<cnt[0]<<endl;
cout<<endl;
} if (ope==0){
break;
}
}
return 0;
}

【例题4-6 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) 题解

    Content 自己去看题面去. Solution 算不上很繁琐的一道大模拟. 首先,既然是输出 \(0\) 才退出,那么在此之前程序应当会执行菜单 \(\Rightarrow\) 子操作 \(\Ri ...

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

    题目链接:https://vjudge.net/problem/UVA-12412 题目大意 略. 分析 比较大规模的模拟,注意输入输出,浮点数精度,还有排名相同的输出顺序,还有一些边界情况处理. 代 ...

  3. A Typical Homework(学生信息管理系统)

    A Typical Homework(a.k.a Shi Xiong Bang Bang Mang) Hi, I am an undergraduate student in institute of ...

  4. 【例题 6-4 UVA - 11988】Broken Keyboard (a.k.a. Beiju Text)

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 会链表的插入操作的话.这个就不难了. 放置两个哨兵节点. 然后模拟插入一个节点的过程就好. 实时修改光标就好->即下一个插入的 ...

  5. Radio Basics for RFID

    Radio Basics for RFID The following is excerpted from Chapter 3: Radio Basics for UHF RFID from the ...

  6. [IR] Compression

    关系:Vocabulary vs. collection size Heaps’ law: M = kTbM is the size of the vocabulary, T is the numbe ...

  7. POJ 3261 可重叠的 k 次最长重复子串【后缀数组】

    这也是一道例题 给定一个字符串,求至少出现 k 次的最长重复子串,这 k 个子串可以重叠.算法分析:这题的做法和上一题差不多,也是先二分答案,然后将后缀分成若干组.不同的是,这里要判断的是有没有一个组 ...

  8. CDQ分治与整体二分学习笔记

     CDQ分治部分 CDQ分治是用分治的方法解决一系列类似偏序问题的分治方法,一般可以用KD-tree.树套树或权值线段树代替. 三维偏序,是一种类似LIS的东西,但是LIS的关键字只有两个,数组下标和 ...

  9. 小结:A* & IDA* & 迭代深搜

    概要: 在dfs中,如果答案的深度很小但是却很宽,而且bfs还不一定好做的情况下,我们就综合bfs的优点,结合dfs的思想,进行有限制的dfs.在这里A*.IDA*和迭代深搜都是对dfs的优化,因此放 ...

随机推荐

  1. Java 7 可执行的 Nashorn,取代 Rhino

    惊现有人把 OpenJDK 上的 Nashorn dump 下来,使得 Java 7 都能够使用.源代码在 https://bitbucket.org/ramonza/nashorn-backport ...

  2. 传智播客C/C++学员荣膺微软&amp;Cocos 2d-x黑客松最佳创新奖

     6月30日,历时32小时的微软开放技术Cocos 2d-x 编程黑客松在北京望京微软大厦成功落下帷幕,这是微软开放技术首次联合Cocos 2d-x 在中国举办黑客松. 此次活动共同拥有包含传智播 ...

  3. luogu2577 [ZJOI2005] 午餐 贪心

    题目大意 THU ACM小组的吃饭计划是这样的:先把所有的人分成两队,并安排好每队中各人的排列顺序,然后一号队伍到一号窗口去排队打饭,二号队伍到二号窗口去排队打饭.每个人打完饭后立刻开始吃,所有人都吃 ...

  4. ConcurrentDictionary中的 TryRemove

    class A { internal int value; } ConcurrentDictionary<int, A> dic = new ConcurrentDictionary< ...

  5. 123D

    后缀数组+单调栈 看了好长时间,最后看了张神的程序才搞懂 意思就是求所有子串*n*(n+1)/2 n是子串出现次数 事实上,lcp可以看成宽度为1,高度为lcp值的长方形,所有lcp放在一起就是一堆长 ...

  6. 利用存储过程插入50W+数据

    转自:https://www.aliyun.com/jiaocheng/1396184.html 首先,建立部门表和员工表: 部门表:   create table dept(   id int un ...

  7. 通过Ajax和SpringBoot交互的示例

    转自:https://blog.csdn.net/oppo5630/article/details/52093898/

  8. 自顶向下(递归)的归并排序和自底向上(循环)的归并排序——java实现

    归并排序有两种实现方式,自顶向下和自底向上.前者的思想是分治法,现将数组逐级二分再二分,分到最小的两个元素后,逐级往上归并,故其核心在于归并.后者的思想相反,采用循环的方式将小问题不断的壮大,最后变成 ...

  9. 第2章 安装Nodejs 2-3 Windows下安装Nodejs

    http://nodejs.org

  10. # --with-http_stub_status_module模块

    作用: 查看nginx的客户端状态 环境检测 nginx -V 查看nginx已经编译的模块中是否包含--with-http_stub_status_module 语法: 效果