【每日编程-312期】PAT单位排行

教育   2024-10-02 10:12   广西  

1085 PAT单位排行


每日编程中遇到任何疑问、意见、建议请公众号留言或直接撩Q474356284(备注每日编程)


输入样例:

10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu

输出样例:

5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2

代码实现:
#include 
#include 
#include 
#include 
#include 
using namespace std;
struct node
{

    string school;
    int tws, ns;
};
bool cmp(node a, node b)
{
    if (a.tws != b.tws)
        return a.tws > b.tws;
    else if (a.ns != b.ns)
        return a.ns < b.ns;
    else
        return a.school < b.school;
}
int main()
{
    int n;
    scanf("%d", &n);
    unordered_map<stringint> cnt;
    unordered_map<stringdouble> sum;
    for (int i = 0; i < n; i++)
    {
        string id, school;
        cin >> id;
        double score;
        scanf("%lf", &score);
        cin >> school;
        for (int j = 0; j < school.length(); j++)
            school[j] = tolower(school[j]);
        if (id[0] == 'B')
            score = score / 1.5;
        else if (id[0] == 'T')
            score = score * 1.5;
        sum[school] += score;
        cnt[school]++;
    }
    vector ans;
    for (auto it = cnt.begin(); it != cnt.end(); it++)
        ans.push_back(node{it->first, (int)sum[it->first], cnt[it->first]});
    sort(ans.begin(), ans.end(), cmp);
    int rank = 0, pres = -1;
    printf("%d\n", (int)ans.size());
    for (int i = 0; i < ans.size(); i++)
    {
        if (pres != ans[i].tws)
            rank = i + 1;
        pres = ans[i].tws;
        printf("%d ", rank);
        cout << ans[i].school;
        printf(" %d %d\n", ans[i].tws, ans[i].ns);
    }
    return 0;
}

明日预告:就不告诉你

做作业的时候,邻座的小盆友问你:“五乘以七等于多少?”你应该不失礼貌地围笑着告诉他:“五十三。”本题就要求你,对任何一对给定的正整数,倒着输出它们的乘积。

输入格式:

输入在第一行给出两个不超过 1000 的正整数 A 和 B,其间以空格分隔。

输出格式:

在一行中倒着输出 A 和 B 的乘积。

输入样例:

5 7

输出样例:

53


灰灰考研
最全的【计算机考研】【软件考研】考研信息! 最丰富的共享资料! 最大程度上帮助学渣狗登上研究生大门!
 最新文章