UVa 12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) 【模拟】

题目链接:UVa 12412


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

Hi, I am an undergraduate student in institute of foreign languages. As you know, C programming is a required course in our university, even if his/her major is far from computer science. I don't like this course at all, as I am not good at computer and I don't wanna even have a try of any programming!! But I have to do the homework in order to pass :( Sh... Could you help me with it? Please keep secret!! I know that you won't say NO to a poor little girl, boy. :)

Task

Write a Student Performance Management System (SPMS).

Concepts

In the SPMS, there will be at most 100 students, each has an SID, a CID, a name and four scores (Chinese, Mathematics, English and Programming).
  • SID (student ID) is a 10-digit number
  • CID (class ID) is a positive integer not greater than 20.
  • Name is a string of no more than 10 letters and digits, beginning with a capital letter. Note that a name cannot contain space characters inside.
  • Each score is a non-negative integer not greater than 100.

Main Menu

When you enter the SPMS, the main menu should be shown like this:
Welcome to Student Performance Management System (SPMS).

1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit

Adding a Student

If you choose 1 from the main menu, the following message should be printed on the screen:
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Then your program should wait for user input. The input lines are always valid (no invalid SID, CID, or name, exactly four scores etc), but the SID may already exist. In that case, simply ignore this line and print the following:
Duplicated SID.
On the other hand, multiple students can have the same name. You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.

Removing a Student

If you choose 2 from the main menu, the following message should be printed on the screen:
Please enter SID or name. Enter 0 to finish.
Then your program should wait for user input, and remove all the students matching the SID or name in the database, and print the following message (it's possible xx=0):
xx student(s) removed.
You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.

Querying Students

If you choose 3 from the main menu, the following message should be printed on the screen:
Please enter SID or name. Enter 0 to finish.
Then your program should wait for user input. If no student matches the SID or name, simply do nothing, otherwise print out all the matching students, in the same order they're added to the database. The format is similar to the input format for "adding a student", but 3 more columns are added: rank (1st column), total score and average score (last two columns). The student with highest total score (considering all classes) received rank-1, and if there are two rank-2 students, the next one would be rank-4. You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.

Showing the Ranklist

If you choose 4 from the main menu, the following message should be printed on the screen:
Showing the ranklist hurts students' self-esteem. Don't do that.
Then the main menu is printed again.

Showing Statistics

If you choose 5 from the main menu, show the statistics, in the following format:
Please enter class ID, 0 for the whole statistics.
When a class ID is entered, print the following statistics. Note that "passed" means to have a score of at least 60.
Chinese
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx

Mathematics
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx

English
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx

Programming
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx

Overall:
Number of students who passed all subjects: xx
Number of students who passed 3 or more subjects: xx
Number of students who passed 2 or more subjects: xx
Number of students who passed 1 or more subjects: xx
Number of students who failed all subjects: xx
Then, the main menu is printed again.

Exiting SPMS

If you choose 0 from the main menu, the program should terminate. Note that course scores and total score should be formatted as integers, but average scores should be formatted as a real number with exactly two digits after the decimal point.

Input

There will be a single test case, ending with a zero entered in the main menu screen. The entire input will be valid. The size of input does not exceed 10KB.

Output

Print out everything as stated in the problem description. You should be able to play around this little program in your machine, with a keyboard and a screen. However, both the input and output may look silly when they're not mixed, as in the keyboard-screen case.

Sample Input

1
0011223344 1 John 79 98 91 100
0022334455 1 Tom 59 72 60 81
0011223344 2 Alice 100 100 100 100
2423475629 2 John 60 80 30 99
0
3
0022334455
John
0
5
1
2
0011223344
0
5
0
4
0

Output for the Sample Input

Welcome to Student Performance Management System (SPMS).

1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit

Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Duplicated SID.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).

1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit

Please enter SID or name. Enter 0 to finish.
2 0022334455 1 Tom 59 72 60 81 272 68.00
Please enter SID or name. Enter 0 to finish.
1 0011223344 1 John 79 98 91 100 368 92.00
3 2423475629 2 John 60 80 30 99 269 67.25
Please enter SID or name. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).

1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit

Please enter class ID, 0 for the whole statistics.
Chinese
Average Score: 69.00
Number of passed students: 1
Number of failed students: 1

Mathematics
Average Score: 85.00
Number of passed students: 2
Number of failed students: 0

English
Average Score: 75.50
Number of passed students: 2
Number of failed students: 0

Programming
Average Score: 90.50
Number of passed students: 2
Number of failed students: 0

Overall:
Number of students who passed all subjects: 1
Number of students who passed 3 or more subjects: 2
Number of students who passed 2 or more subjects: 2
Number of students who passed 1 or more subjects: 2
Number of students who failed all subjects: 0

Welcome to Student Performance Management System (SPMS).

1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit

Please enter SID or name. Enter 0 to finish.
1 student(s) removed.
Please enter SID or name. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).

1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit

Please enter class ID, 0 for the whole statistics.
Chinese
Average Score: 59.50
Number of passed students: 1
Number of failed students: 1

Mathematics
Average Score: 76.00
Number of passed students: 2
Number of failed students: 0

English
Average Score: 45.00
Number of passed students: 1
Number of failed students: 1

Programming
Average Score: 90.00
Number of passed students: 2
Number of failed students: 0

Overall:
Number of students who passed all subjects: 0
Number of students who passed 3 or more subjects: 2
Number of students who passed 2 or more subjects: 2
Number of students who passed 1 or more subjects: 2
Number of students who failed all subjects: 0

Welcome to Student Performance Management System (SPMS).

1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit

Showing the ranklist hurts students' self-esteem. Don't do that.
Welcome to Student Performance Management System (SPMS).

1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit

(本来没打算写,但是从网上搜题解时发现很多代码都标明蜜汁WA,所以写下这篇博客指出此题的坑点)


题目大意:

编写一个成绩管理系统,对应的每次输入都作出相应的回复。


解题思路:

直接模拟即可,有很多细节要注意。


注意细节:

1.计算平均分的时候要注意一下精度问题。为防止精度丢失,我在每个计算出的精度后面都加上了eps(1e-5)。
2.计算rank时,不要忘记考虑并列的情况。(如果有两个学生成绩并列第一,那么除他们外最高分就是第三名)。
3.当从主菜单输入4时,只返回一句话,那句话中的 ' 应该是英文的,直接从描述中复制过来是中文的。
4.看到有些博客中写到要防止除0的情况发生。我的程序中除0就是在求单科ave时可能出现的,但是经过测试,数据中并没有这种情况,所以可以不必考虑。
【注】以上就是我出现的错误,其他的细节都是很好发现的了。如果没出现这些错误但是你还过不了的话,不要着急,再仔细想想哪些细节出了问题,或者是私信/留言给我,作为一个 在这上面WA到怀疑XX之后还坚持不懈最终A了这道题的快乐的咸鱼,我会乐意帮助你的。

Mycode:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX = 10005;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;

int op, tot;
struct node
{
    int chi, mat, eng, pro, sum, rk;  //四课分数
    string SID, CID, name;
    double ave;
    bool flag;
    int pas;

} a[MAX];

bool cmp(int A, int B)
{
    return A > B;
}

void hello()
{
    puts("Welcome to Student Performance Management System (SPMS).");
    puts("");
    puts("1 - Add");
    puts("2 - Remove");
    puts("3 - Query");
    puts("4 - Show ranking");
    puts("5 - Show Statistics");
    puts("0 - Exit");
    puts("");
}

void work1()
{
    string si, ci, na;
    int c, m, e, p;
    while(1)
    {
        puts("Please enter the SID, CID, name and four scores. Enter 0 to finish.");
        cin >> si;
        if(si == "0") return ;

        cin >> ci >> na >> c >> m >> e >> p;
        bool f = true;
        for(int i = 0; i < tot; ++i)
        {
            if(a[i].flag && a[i].SID == si)
            {
                puts("Duplicated SID.");
                f = false;
                break;
            }
        }
        if(f)
        {
            a[tot].SID = si;
            a[tot].CID = ci;
            a[tot].name = na;
            a[tot].chi = c;
            a[tot].eng = e;
            a[tot].mat = m;
            a[tot].pro = p;
            a[tot].sum = c + e + m + p;
            a[tot].ave = (c + e + m + p) / 4.0 + eps;
            a[tot].flag = true;
            ++tot;
        }
    }
}

void work2()
{
    string tt;
    while(1)
    {
        puts("Please enter SID or name. Enter 0 to finish.");
        cin >> tt;
        if(tt == "0") return ;
        int cnt = 0;

        for(int i = 0; i < tot; ++i)
        {
            if(a[i].flag)
            {
                if(a[i].name == tt || a[i].SID == tt)
                {
                    a[i].flag = false;
                    cnt++;
                }
            }
        }
        printf("%d student(s) removed.\n", cnt);
    }
}

void work3()
{
    //每次查询都计算一下rank
    int tem[MAX], rrk[MAX], srk = 1, now = 0;
    for(int i = 0; i < tot; ++i)
    {
        if(a[i].flag)
            tem[now++] = a[i].sum;
    }
    sort(tem, tem + now, cmp);
    rrk[0] = 1;
    srk++;
    for(int i = 1; i < now; ++i)
    {
        if(tem[i] != tem[i-1])
            rrk[i] = srk;
        else
            rrk[i] = rrk[i-1];
        ++srk;
    }
    for(int i = 0; i < tot; ++i)
    {
        if(a[i].flag)
        {
            for(int t = 0; t < now; ++t)
            {
                if(a[i].sum == tem[t])
                {
                    a[i].rk = rrk[t];
                    break;
                }
            }
        }
    }

    string tt;
    while(1)
    {
        puts("Please enter SID or name. Enter 0 to finish.");
        cin >> tt;
        if(tt == "0") return ;

        for(int i = 0; i < tot; ++i)
        {
            if(a[i].flag && (a[i].SID == tt || a[i].name == tt))
            {
                cout << a[i].rk << " " << a[i].SID << " " << a[i].CID << " " << a[i].name;
                printf(" %d %d %d %d %d %.2f\n", a[i].chi, a[i].mat, a[i].eng, a[i].pro, a[i].sum, a[i].ave);
            }
        }
    }
}

void work4()
{
    puts("Showing the ranklist hurts students' self-esteem. Don't do that.");
    return ;
}

void work5()
{
    puts("Please enter class ID, 0 for the whole statistics.");
    string tt;
    cin >> tt;
    int pas, fai, yy[5], qq;
    double suma, cnta, avea;

    puts("Chinese");
    suma = cnta = pas = fai = 0;
    for(int i = 0; i < tot; ++i)
    {
        if(a[i].flag && (a[i].CID == tt || tt == "0"))
        {
            ++cnta;
            suma += a[i].chi;
            if(a[i].chi >= 60)
                ++pas;
            else
                ++fai;
        }
    }
    if(cnta == 0)
        avea = 0;
    else
        avea = suma / cnta + eps;
    printf("Average Score: %.2f\n", avea);
    printf("Number of passed students: %d\n", pas);
    printf("Number of failed students: %d\n", fai);
    puts("");

    puts("Mathematics");
    suma = cnta = pas = fai = 0;
    for(int i = 0; i < tot; ++i)
    {
        if(a[i].flag && (a[i].CID == tt || tt == "0"))
        {
            ++cnta;
            suma += a[i].mat;
            if(a[i].mat >= 60)
                ++pas;
            else
                ++fai;
        }
    }
    if(cnta == 0)
        avea = 0;
    else
        avea = suma / cnta + eps;
    printf("Average Score: %.2f\n", avea);
    printf("Number of passed students: %d\n", pas);
    printf("Number of failed students: %d\n", fai);
    puts("");

    puts("English");
    suma = cnta = pas = fai = 0;
    for(int i = 0; i < tot; ++i)
    {
        if(a[i].flag && (a[i].CID == tt || tt == "0"))
        {
            ++cnta;
            suma += a[i].eng;
            if(a[i].eng >= 60)
                ++pas;
            else
                ++fai;
        }
    }
    if(cnta == 0)
        avea = 0;
    else
        avea = suma / cnta + eps;
    printf("Average Score: %.2f\n", avea);
    printf("Number of passed students: %d\n", pas);
    printf("Number of failed students: %d\n", fai);
    puts("");

    puts("Programming");
    suma = cnta = pas = fai = 0;
    for(int i = 0; i < tot; ++i)
    {
        if(a[i].flag && (a[i].CID == tt || tt == "0"))
        {
            ++cnta;
            suma += a[i].pro;
            if(a[i].pro >= 60)
                ++pas;
            else
                ++fai;
        }
    }
    if(cnta == 0)
        avea = 0;
    else
        avea = suma / cnta + eps;
    printf("Average Score: %.2f\n", avea);
    printf("Number of passed students: %d\n", pas);
    printf("Number of failed students: %d\n", fai);
    puts("");

    memset(yy, 0, sizeof(yy));
    puts("Overall:");
    for(int i = 0; i < tot; ++i)
    {
        if(a[i].flag && (a[i].CID == tt || tt == "0"))
        {
            qq = (a[i].chi >= 60) + (a[i].eng >= 60) + (a[i].pro >= 60) + (a[i].mat >= 60);
            yy[qq]++;
        }
    }
    printf("Number of students who passed all subjects: %d\n", yy[4]);
    printf("Number of students who passed 3 or more subjects: %d\n", yy[4] + yy[3]);
    printf("Number of students who passed 2 or more subjects: %d\n", yy[4] + yy[3] + yy[2]);
    printf("Number of students who passed 1 or more subjects: %d\n", yy[4] + yy[3] + yy[2] + yy[1]);
    printf("Number of students who failed all subjects: %d\n", yy[0]);
    puts("");
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out1.txt","w",stdout);

    hello();
    while(cin >> op && op)
    {
        if(op == 1)
            work1();
        else if(op == 2)
            work2();
        else if(op == 3)
            work3();
        else if(op == 4)
            work4();
        else if(op == 5)
            work5();
        hello();
    }

//    fclose(stdin);
//    fclose(stdout);
    return 0;
}



  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
A typical project life cycle consists of five main phases: 1. Initiation: In this phase, the project is identified, defined, and approved. The project team is assembled, and the project charter is created. The outcome of this phase is the project charter, which outlines the project purpose, goals, objectives, deliverables, stakeholders, and resources required. 2. Planning: In this phase, the project plan is developed, and the project scope, schedule, budget, and resources are defined. The project team identifies potential risks and develops risk management strategies. The outcome of this phase is the project plan, which outlines the detailed project scope, schedule, budget, and resource requirements. 3. Execution: In this phase, the project plan is put into action, and the project deliverables are produced. The project team implements the project management and quality assurance processes. The outcome of this phase is the completed deliverables. 4. Monitoring and Control: In this phase, the project progress is monitored, and the project performance is measured against the project plan. Any issues or deviations from the plan are identified, and corrective actions are taken. The outcome of this phase is the updated project plan, which reflects any changes made during the monitoring and control phase. 5. Closure: In this phase, the project is completed, and the project deliverables are accepted by the stakeholders. The project team conducts a project review and documents the lessons learned. The outcome of this phase is the project closure report, which outlines the project success, challenges, and recommendations for future projects. Overall, the project life cycle is a systematic approach to managing projects from initiation to closure, ensuring that projects are completed on time, within budget, and to the satisfaction of stakeholders.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值