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

PE,弃疗了。

#include <iostream>
#include <string>
#include <cstdio>
#include <iomanip>
#include <algorithm>
using namespace std;
struct stu{
    int CID,C[4],SUM=0;
    string SID,NAME;
};
string wel[7]={"Welcome to Student Performance Management System (SPMS).",
               "1 - Add",
               "2 - Remove",
               "3 - Query",
               "4 - Show ranking",
               "5 - Show Statistics",
               "0 - Exit"};
string info[7]={"Duplicated SID.",
                "Please enter the SID, CID, name and four scores. Enter 0 to finish.",
                "Please enter SID or name. Enter 0 to finish.",
                "Showing the ranklist hurts students' self-esteem. Don't do that.",
                "Please enter class ID, 0 for the whole statistics.",
                " student(s) removed.",
                "Showing the ranklist hurts students' self-esteem. Don't do that."};
string course[4]={"Chinese",
                  "Mathematics",
                  "English",
                  "Programming"};
void welcome()
{
    int i;
    for(i=0;i<7;i++){
        cout<<wel[i]<<endl;
        if(!i)
            cout<<endl;
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    stu s[1000];
    int n=0,c[4],k,cid,i,j,flag,count;
    string sid,name,match;
    while(1){
        welcome();
        cout<<endl;
        cin>>k;
        if(!k)
            break;
        else if(k==1){
            while(1){
                cout<<info[1]<<endl;
                flag=0;
                cin>>sid;
                if(sid=="0")
                    break;
                else
                    cin>>cid>>name>>c[0]>>c[1]>>c[2]>>c[3];
                for(i=0;i<n;i++)
                    if(s[i].SID==sid){
                        cout<<info[0]<<endl;
                        flag=1;
                        break;
                    }
                if(flag)
                    continue;
                else{
                    s[n].SID=sid,s[n].CID=cid,s[n].NAME=name,s[n].C[0]=c[0],s[n].C[1]=c[1],s[n].C[2]=c[2],s[n].C[3]=c[3],s[n].SUM=c[0]+c[1]+c[2]+c[3];
                    n++;
                }
            }
        }
        else if(k==2){
            while(1){
                cout<<info[2]<<endl;
                cin>>match;
                if(match=="0")
                    break;
                count=0;
                for(i=0;i<n;i++){
                    if((s[i].NAME==match&&s[i].SID!="0")||s[i].SID==match){
                        count++;
                        s[i].SID="0";
                    }
                }
                cout<<count<<info[5]<<endl;
            }
        }
        else if(k==3){
            while(1){
                cout<<info[2]<<endl;
                cin>>match;
                if(match=="0")
                    break;
                flag=0;
                for(i=0;i<n;i++){
                    if((s[i].NAME==match&&s[i].SID!="0")||s[i].SID==match){
                        count=1,flag=1;
                        for(j=0;j<n;j++){
                            if(s[j].SID!="0"&&s[j].SUM>s[i].SUM)
                                count++;
                        }
                        if(flag)
                            cout<<count<<' '<<s[i].SID<<' '<<s[i].CID<<' '<<s[i].NAME<<' '<<s[i].C[0]<<' '<<s[i].C[1]<<' '<<s[i].C[2]<<' '<<s[i].C[3]<<' '<<s[i].SUM<<' '<<fixed<<setprecision(2)<<(double)s[i].SUM/4+1e-6<<endl;
                    }
                }
            }
        }
        else if(k==4){
            cout<<info[3]<<endl;
        }
        else if(k==5){
            cout<<info[4]<<endl;
            cin>>cid;
            int total[4]={0},coursepass[4]={0},totalpass[5]={0},num=0;
            for(i=0;i<n;i++){
                if(s[i].SID!="0"&&(s[i].CID==cid||!cid)){
                    count=0,num++;
                    for(j=0;j<4;j++){
                        if(s[i].C[j]>=60)
                            count++,coursepass[j]++;
                        total[j]+=s[i].C[j];
                    }
                    totalpass[count]++;
                }
            }
            for(i=0;i<4;i++){
                cout<<course[i]<<endl;
                cout<<"Average Score: "<<fixed<<setprecision(2)<<(double)total[i]/max(num,1)+1e-6<<endl;
                cout<<"Number of passed students: "<<coursepass[i]<<endl;
                cout<<"Number of failed students: "<<num-coursepass[i]<<endl;
                cout<<endl;
            }
            cout<<"Overall: "<<endl;
            cout<<"Number of students who passed all subjects: "<<totalpass[4]<<endl;
            cout<<"Number of students who passed 3 or more subjects: "<<totalpass[3]+totalpass[4]<<endl;
            cout<<"Number of students who passed 2 or more subjects: "<<totalpass[2]+totalpass[3]+totalpass[4]<<endl;
            cout<<"Number of students who passed 1 or more subjects: "<<totalpass[1]+totalpass[2]+totalpass[3]+totalpass[4]<<endl;
            cout<<"Number of students who failed all subjects: "<<totalpass[0]<<endl;
            cout<<endl;
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值