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。。。。

AC了的代碼(大佬的代碼)

#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;elsev.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;
}

我的WA了的代碼(心塞)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
struct node
{char SID[15];int CID;char name[15];int Chi;int Eng;int Math;int Pra;int all;double average;bool ju;int paiming;int numpass;int id;
}Stu[1000];
bool cmp(node a,node b)
{return a.all>b.all;
}
bool cmp1(node a,node b)
{return a.id<b.id;
}
int cnt;
void miue()
{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");
}
int choice_1()
{printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");char a[15];char nape[15];int b;int c1,c2,c3,c4;scanf("%s",a);if(a[0]=='0'&&strlen(a)==1)return 0;scanf("%d %s %d %d %d %d",&b,nape,&c1,&c2,&c3,&c4);rep(i,1,cnt) {if(strlen(Stu[i].SID)!=0&&Stu[i].ju==false) continue;if(strcmp(Stu[i].SID,a)==0) {printf("Duplicated SID.\n");return 1;}}cnt++;strcpy(Stu[cnt].SID,a);Stu[cnt].CID=b;strcpy(Stu[cnt].name,nape);Stu[cnt].Chi=c1;Stu[cnt].Math=c2;Stu[cnt].Eng=c3;Stu[cnt].Pra=c4;Stu[cnt].all=c1+c2+c3+c4;Stu[cnt].average=(double)Stu[cnt].all/4.0;Stu[cnt].ju=true;int k=4;if(c1<60) k--;if(c2<60) k--;if(c3<60) k--;if(c4<60) k--;Stu[cnt].numpass=k;Stu[cnt].id=cnt;return 1;
}
int choice_2()
{printf("Please enter SID or name. Enter 0 to finish.\n");char s[15];int num=0;scanf("%s",s);if(s[0]=='0'&&strlen(s)==1) return 0;if(s[0]>='A'&&s[0]<='Z'){rep(i,1,cnt) {if(Stu[i].ju==false) continue;if(strcmp(Stu[i].name,s)==0) {Stu[i].ju=false;num++;}}}else {rep(i,1,cnt) {if(Stu[i].ju==false) continue;if(strcmp(Stu[i].SID,s)==0) {Stu[i].ju=false;num++;}}}printf("%d student(s) removed.\n",num);return 1;
}
int choice_3()
{sort(Stu+1,Stu+cnt+1,cmp);int np1=1,np2=1;int nape;int i=1;while(!Stu[i].ju) i++;Stu[i].paiming=np1;nape=Stu[i].all;i++;for(;i<=cnt;i++) {if(Stu[i].ju==false) continue;else {if(Stu[i].all==nape) {Stu[i].paiming=np1;np2++;}else {np2++;nape=Stu[i].all;Stu[i].paiming=np2;np1=np2;}}}sort(Stu+1,Stu+1+cnt,cmp1);printf("Please enter SID or name. Enter 0 to finish.\n");char s[15];scanf("%s",s);if(s[0]=='0'&&strlen(s)==1) return 0;if(s[0]>='A'&&s[0]<='Z'){rep(i,1,cnt) {if(strcmp(Stu[i].name,s)==0&&Stu[i].ju==true) {printf("%d %s %d %s %d %d %d %d %d %.2f\n",Stu[i].paiming,Stu[i].SID,Stu[i].CID,Stu[i].name,Stu[i].Chi,Stu[i].Math,Stu[i].Eng,Stu[i].Pra,Stu[i].all,Stu[i].average);}}}else {rep(i,1,cnt) {if(strcmp(Stu[i].SID,s)==0&&Stu[i].ju==true) {printf("%d %s %d %s %d %d %d %d %d %.2f\n",Stu[i].paiming,Stu[i].SID,Stu[i].CID,Stu[i].name,Stu[i].Chi,Stu[i].Math,Stu[i].Eng,Stu[i].Pra,Stu[i].all,Stu[i].average);}}}return 1;
}
void choice_4()
{printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n");
}
void choice_5()
{printf("Please enter class ID, 0 for the whole statistics.\n");int ClassID;double num=0.0;double allC=0.0;double allM=0.0;double allE=0.0;double allP=0.0;double aveC=0.0;double aveM=0.0;double aveE=0.0;double aveP=0.0;int numPC=0,numPM=0,numPE=0,numPP=0;int numFC=0,numFM=0,numFE=0,numFP=0;int pass4=0,pass3=0,pass2=0,pass1=0,pass0=0;scanf("%d",&ClassID);if(ClassID!=0) {rep(i,1,cnt) {if(Stu[i].ju==false) continue;if(Stu[i].CID==ClassID) {allC=allC+Stu[i].Chi;allM=allM+Stu[i].Math;allE=allE+Stu[i].Eng;allP=allP+Stu[i].Pra;if(Stu[i].Chi>=60) numPC++;else numFC++;if(Stu[i].Math>=60) numPM++;else numFM++;if(Stu[i].Eng>=60) numPE++;else numFE++;if(Stu[i].Pra>=60) numPP++;else numFP++;if(Stu[i].numpass==4) pass4++;if(Stu[i].numpass==3) pass3++;if(Stu[i].numpass==2) pass2++;if(Stu[i].numpass==1) pass1++;if(Stu[i].numpass==0) pass0++;num++;}}}else {rep(i,1,cnt) {if(Stu[i].ju==false) continue;allC=allC+Stu[i].Chi;allM=allM+Stu[i].Math;allE=allE+Stu[i].Eng;allP=allP+Stu[i].Pra;if(Stu[i].Chi>=60) numPC++;else numFC++;if(Stu[i].Math>=60) numPM++;else numFM++;if(Stu[i].Eng>=60) numPE++;else numFE++;if(Stu[i].Pra>=60) numPP++;else numFP++;if(Stu[i].numpass==4) pass4++;if(Stu[i].numpass==3) pass3++;if(Stu[i].numpass==2) pass2++;if(Stu[i].numpass==1) pass1++;if(Stu[i].numpass==0) pass0++;num++;}}if(num!=0) {aveC=allC/num;aveM=allM/num;aveE=allE/num;aveP=allP/num;}else aveC=aveM=aveE=aveP=0;printf("Chinese\n");if(aveC!=0) printf("Average Score: %.2lf\n",aveC);else printf("Average Score: -nan\n");printf("Number of passed students: %d\n",numPC);printf("Number of failed students: %d\n\n",numFC);printf("Mathematics\n");if(aveM!=0) printf("Average Score: %.2lf\n",aveM);else printf("Average Score: -nan\n");printf("Number of passed students: %d\n",numPM);printf("Number of failed students: %d\n\n",numFM);printf("English\n");if(aveE!=0) printf("Average Score: %.2lf\n",aveE);else printf("Average Score: -nan\n");printf("Number of passed students: %d\n",numPE);printf("Number of failed students: %d\n\n",numFE);printf("Programming\n");if(aveP!=0) printf("Average Score: %.2lf\n",aveP);else printf("Average Score: -nan\n");printf("Number of passed students: %d\n",numPP);printf("Number of failed students: %d\n\n",numFP);printf("Overall:\n");printf("Number of students who passed all subjects: %d\n",pass4);printf("Number of students who passed 3 or more subjects: %d\n",pass3+pass4);printf("Number of students who passed 2 or more subjects: %d\n",pass2+pass3+pass4);printf("Number of students who passed 1 or more subjects: %d\n",pass1+pass2+pass3+pass4);printf("Number of students who failed all subjects: %d\n\n",pass0);
}
int main() 
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);//ios::sync_with_stdio(0),cin.tie(0);int idx;miue();while(scanf("%d",&idx)&&idx){int nape;if(idx==1) {while(1) {nape=choice_1();if(nape==0) break;}}if(idx==2) {while(1) {nape=choice_2();if(nape==0) break;}}if(idx==3) {while(1) {nape=choice_3();if(nape==0) break;}}if(idx==4) {choice_4();}if(idx==5) {choice_5();}miue();}return 0;
}

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/536314.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/536314.shtml
英文地址,請注明出處:http://en.pswp.cn/news/536314.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【思維】draw!

題目&#xff1a; You still have partial information about the score during the historic football match. You are given a set of pairs (ai,bi)(ai,bi), indicating that at some point during the match the score was "aiai: bibi". It is known that if t…

【數學】Birthday

題目&#xff1a; Cowboy Vlad has a birthday today! There are nn children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a…

【遞推】Ayoub and Lost Array

題目&#xff1a;Ayoub had an array aa of integers of size nn and this array had two interesting properties: All the integers in the array were between ll and rr (inclusive). The sum of all the elements was divisible by 33. Unfortunately, Ayoub has lost hi…

Super-palindrome【字符串+思維】

Super-palindrome 時間限制: 1 Sec 內存限制: 128 MB 提交: 595 解決: 231 [提交] [狀態] [命題人:admin] 題目描述 You are given a string that is consisted of lowercase English alphabet. You are supposed to change it into a super-palindrome string in minimum ste…

Hakase and Nano【博弈】

Hakase and Nano 時間限制: 1 Sec 內存限制: 128 MB 提交: 533 解決: 155 [提交] [狀態] [命題人:admin] 題目描述 Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). There are n packs of pebbles, and the i-th pack contains ai pebble…

【思維】過分的謎題

題目描述 2060年是云南中醫學院的百年校慶&#xff0c;于是學生會的同學們搞了一個連續猜謎活動&#xff1a;共有10個謎題&#xff0c;現在告訴所有人第一個謎題&#xff0c;每個謎題的答案就是下一個謎題的線索....成功破解最后一個謎題后&#xff0c;答案就是指向獎勵的線索…

【bfs】調酒壺里的酸奶

題目描述 最近小w學了一手調酒的技巧&#xff0c;這么帥的操作&#xff0c;說不定能靠這個俘獲女神的芳心&#xff0c;為了在女神面前露一手&#xff0c;他想在學校里建一個"pub"&#xff0c;但是顯然學校不可能讓他真的建一個"pub"&#xff0c;那么他退而…

【dfs】Election of Evil

題目描述 Dylan is a corrupt politician trying to steal an election. He has already used a mind-control technique to enslave some set U of government representatives. However, the representatives who will be choosing the winner of the election is a di?ere…

【思維】Iranian ChamPions Cup

題目描述 The Iranian ChamPions Cup (ICPC), the most prestigious football league in Iran, is reaching its end, and people are eagerly waiting for the finals, which happened to be between the two most popular Iranian teams, Persepolis and Esteghlal. The ICP…

【數學】Chaarshanbegaan at Cafebazaar

題目描述 Chaarshanbegaan is a gathering event at Cafebazaar similar to TGIF events at Google. Some entertainment programs like pantomime, foosball, Xbox/PS4, and several board games are part of the event. You are going to set up a dart game in Chaarshanbe…

【思維】Congestion Charging Zone

題目描述 Tehran municipality has set up a new charging method for the Congestion Charging Zone (CCZ) which controls the passage of vehicles in Tehran’s high-congestion areas in the congestion period (CP) from 6:30 to 19:00. There are plate detection came…

【二分】LED

題目描述 A Light-Emitting Diode (LED) is a semiconductor light source, which emits light when an electric current of voltage higher than a threshhold is applied to its leads. ACM R&D recently reported that they have succesfully developed a new LED, na…

【差分數組】Master of GCD

題目描述 Hakase has n numbers in a line. At fi rst, they are all equal to 1. Besides, Hakase is interested in primes. She will choose a continuous subsequence [l, r] and a prime parameter x each time and for every l≤i≤r, she will change ai into ai*x. To…

【模擬】Ground Defense

題目描述 You are a denizen of Linetopia, whose n major cities happen to be equally spaced along an east-west line. In fact, they are often numbered in order from 1 to n, where 1 is the westmost city and n is the eastmost city. Linetopia was a lovely plac…

【模擬】Bulbs

題目描述 Greg has an m n grid of Sweet Lightbulbs of Pure Coolness he would like to turn on. Initially, some of the bulbs are on and some are off. Greg can toggle some bulbs by shooting his laser at them. When he shoots his laser at a bulb, it toggles th…

【模擬】Ingenious Lottery Tickets

題目描述 Your friend Superstitious Stanley is always getting himself into trouble. This time, in his Super Lotto Pick and Choose plan, he wants to get rich quick by choosing the right numbers to win the lottery. In this lottery, entries consist of six dis…

【數學】Hunter’s Apprentice

題目描述 When you were five years old, you watched in horror as a spiked devil murdered your parents. You would have died too, except you were saved by Rose, a passing demon hunter. She ended up adopting you and training you as her apprentice. Rose’s cur…

【模擬】Thanks, TuSimple!

題目鏈接&#xff1a;http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId5979 Thanks, TuSimple! Time Limit: 1 Second Memory Limit: 65536 KB In the very first sentence of the very first problem, we would like to give our sincere thanks to TuSimple,…

【二維差分】Monitor

Monitor 題目&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid6514 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 163840/163840 K (Java/Others) Total Submission(s): 600 Accepted Submission(s): 190 Problem Description Xiaoteng has a la…

【數學】MORE XOR

Given a sequence of nnn numbers a1,a2,?&ThinSpace;,ana_1, a_2,\cdots, a_na1?,a2?,?,an? and three functions. Define a function f(l,r)f(l,r)f(l,r) which returns ⊕a[x](l≤x≤r)\oplus a[x] (l \le x \le r)⊕a[x](l≤x≤r). The \oplus⊕ represents excl…