PAT1025 PAT Ranking

Sample Input:

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
Sample Output:
9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4

 

 

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <algorithm>
using namespace std;

struct STUDENT
{
    string regnum;
    int score;
    int location;
    int totalrank;
    int locationrank;
    STUDENT()
    {
        score = 0;
        location = 0;
        totalrank = 0;
        locationrank = 0;
    }
};

bool greatermark(const STUDENT& s1,const STUDENT& s2)   
{   
    return   s1.score   >   s2.score;   
}


bool lessregnum(const STUDENT& s1,const STUDENT& s2)   
{   
    return   s1.regnum   <   s2.regnum;   
}

bool sortByScore(STUDENT a,STUDENT b)  
{  
    if(a.score != b.score)  
        return  a.score > b.score;  

    return a.regnum < b.regnum;  
} 


int main()
{
    int N;
    cin>>N;
    int i = 0;
    vector<STUDENT> VArray[100];
    while(N--)
    {
        int K;
        cin>>K;
        vector<STUDENT> V;
        while(K--)
        {
            STUDENT stu;
            cin>>stu.regnum>>stu.score;
            stu.location = i + 1;
            V.push_back(stu);
        }
        sort(V.begin(), V.end(), sortByScore);


        int forword = -1;
        int irank = 0;
        int realrank = 0;
        vector<STUDENT>::iterator iter = V.begin();
        while(iter != V.end())
        {
            ++realrank;
            if (forword != (*iter).score)
            {
                irank = realrank;
                (*iter).locationrank = realrank;
                forword = (*iter).score;
            }
            else
            {
                (*iter).locationrank = irank;
            }
            iter++;
        }
        VArray[i] = V;
        i++;
    }

    vector<STUDENT> VSum;
    for (int i = 0; i < 100; i++)
    {
        VSum.insert(VSum.end(),VArray[i].begin(),VArray[i].end());
    }
    sort(VSum.begin(), VSum.end(), sortByScore);

    int forword = -1;
    int irank = 0;
    int realrank = 0;
    vector<STUDENT>::iterator iter = VSum.begin();
    while(iter != VSum.end())
    {
        ++realrank;
        if (forword != (*iter).score)
        {
            irank = realrank;
            (*iter).totalrank = realrank;
            forword = (*iter).score;
        }
        else
        {
            (*iter).totalrank = irank;
        }
        iter++;
    }

    cout<<VSum.size();
    cout.setf(ios::fixed);
    for (int i = 0; i < VSum.size(); i++)
    {
        cout<<endl;
        cout<<VSum[i].regnum<<" "<<VSum[i].totalrank<<" "<<VSum[i].location<<" "<<VSum[i].locationrank;
    }
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值