1141 PAT Ranking of Institutions(25 分)

按照题意写完提交最后一个测试点过不去

Score = ScoreB/1.5 + ScoreA + ScoreT*1.5

因为score是整型而1.5是小数,乘除的过程中会出现精度的问题

所以我的解决方案是先将B,A,T三个级别的分数分开存放,输入数据处理好后再按照系数算出score的值

代码如下

 

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
#include<map>
using namespace std;

struct school{
    string school;
    int Bscore;
    int Ascore;
    int Tscore;
    int score;
    int Rank;
    int cnt;

}p[100005];

string change(string str)
{
    for(int i=0;i<str.size();i++)
    {
        if(str[i]>='A' && str[i]<='Z')
        {
            str[i] += ('a'-'A');
        }
    }
    return str;

}

bool cmp(school a, school b)
{
    if(a.score != b.score){
        return a.score > b.score;
    }
    else if(a.cnt != b.cnt)
    {
        return a.cnt < b.cnt;
    }
    else if(a.school != b.school)
    {
        return a.school < b.school;
    }
}
int main()
{

    int n;
    scanf("%d",&n);

    if(n==0) return 0;

    map<string, int> mp;

    string num;
    int score;
    string school;
    int cnt = 0;
    for(int i=0;i<n;i++)
    {
        cin>>num>>score>>school;

        school = change(school);


        //cout<<school<<endl;
        if(mp.count(school) == 0)
        {
            mp[school] = cnt++;
            p[ mp[school] ].school = school;
        }

            p[ mp[school] ].cnt++;

        if(num[0]=='B') {
            p[ mp[school] ].Bscore += score;
        }
        else if(num[0]=='A') {
            p[ mp[school] ].Ascore += score;
        }
        else if(num[0]=='T') {
            p[ mp[school] ].Tscore += score;
        }

    }


    for(int i=0;i<cnt;i++)
    {
        p[i].score = (p[i].Bscore*2)/3 + p[i].Ascore + (p[i].Tscore*3)/2;
    }

    sort(p,p+cnt,cmp);

    for(int i=0;i<cnt;i++)
    {
        if(i==0)
        {
            p[i].Rank = 1;
        }
        else if(p[i].score == p[i-1].score)
        {
            p[i].Rank = p[i-1].Rank;
        }
        else
        {
            p[i].Rank = i+1;
        }
    }

    printf("%d\n",cnt);

    for(int i=0;i<cnt;i++)
    {
        cout<<p[i].Rank<<" "<<p[i].school<<" "<<p[i].score<<" "<<p[i].cnt<<endl;
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值