码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ What is your grade?

时间:2014-09-07 10:57:54      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   os   io   ar   for   art   

题目:

 
Problem Description
“Point, point, life of student!”
This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course.
There are 5 problems in this final exam. And I will give you 100 points if you can solve all 5 problems; of course, it is fairly difficulty for many of you. If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems). Analogically(以此类推), you can get 85、80、75、70、65、60. But you will not pass this exam if you solve nothing problem, and I will mark your score with 50.
Note, only 1 student will get the score 95 when 3 students have solved 4 problems.
I wish you all can pass the exam!
Come on!
 
Input
Input contains multiple test cases. Each test case contains an integer N (1<=N<=100, the number of students) in a line first, and then N lines follow. Each line contains P (0<=P<=5 number of problems that have been solved) and T(consumed time). You can assume that all data are different when 0<p.
A test case starting with a negative integer terminates the input and this test case should not to be processed.
 
Output
Output the scores of N students in N lines for each case, and there is a blank line after each case.
 
Sample Input
4
5 06:30:17
4 07:31:27
4 08:12:12
4 05:23:13
1
5 06:30:17
-1
 
Sample Output
100
90
90
95

100

比较简单的一道题目……首先根据耗时和解决题目的数量进行排序,然后根据题目要求进行分数换算,这里面if语句的顺序弄反了让我提交了好几次才ac...

最后再根据输入位置进行排序输出...

写的有点麻烦

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct Student
{
    int p;
    string s;
    int grade;
    int order;
};
bool cmp(const Student&a,const Student&b)
{
    if(a.p!=b.p)
        return a.p>b.p;
    else
        return a.s<b.s;
}
bool cmp2(const Student&a,const Student&b)
{
    return a.order<b.order;
}
int main()
{
    int n;
    while(scanf_s("%d",&n)&&n>0)
    {
        vector<Student> t;
        Student temp;
        int k=n;
        temp.p=100;
        t.push_back(temp);
        int j=0;
        int count[6]={0};
        while(n--)
        {
            cin>>temp.p>>temp.s;
            temp.order=j++;
            t.push_back(temp);
            
        }
        sort(t.begin()+1,t.end(),cmp);
        //temp.p=100;
        //t.push_back(temp);
        for (int i = 1; i < k+1; i++)
        {
            count[t[i].p]++;
        }
        for (int i = 0; i < 6; i++)
        {
            count[i]==1?count[i]=-5:count[i]/=2;
        }
        for (int i = 1; i < k+1; i++)
        {
            if(count[t[i].p]==-5)
                t[i].grade=50+t[i].p*10+5;
            if (count[t[i].p]==0)
            {
                t[i].grade=50+t[i].p*10;
            }
            if(count[t[i].p]>0)
            {
                t[i].grade=50+t[i].p*10+5;
                count[t[i].p]--;
            }

            if(t[i].p==5||t[i].p==0)
                t[i].grade=50+t[i].p*10;    
        }
        sort(t.begin()+1,t.end(),cmp2);
        for (int i = 1; i < k+1; i++)
        {
            cout<<t[i].grade<<endl;
        }
        cout<<endl;
    }
    return 0;
}

 

HDOJ What is your grade?

标签:des   style   blog   color   os   io   ar   for   art   

原文地址:http://www.cnblogs.com/makeitsure/p/3960191.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!