PAT甲级-1012 The Best Rank (25分)

点击链接PAT甲级-AC全解汇总

题目:
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

StudentID  C  M  E  A
310101     98 85 88 90
310102     70 95 88 84
310103     82 87 94 88
310104     91 91 91 91

Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input Specification:
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output Specification:
For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

The priorities of the ranking methods are ordered as A > C > M >E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

If a student is not on the grading list, simply output N/A.

Sample Input:

5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999

Sample Output:

1 C
1 M
1 E
1 A
3 A
N/A

题意:
输入学生 以及三门课的成绩,然后每输入一个学生的id就打印最高的排名和对应排名的分类。
排名分成三门课的单独排名和平均分的排名。

我的代码:

#include<bits/stdc++.h>
using namespace std;
class Stu{
public:
    Stu(){};
    ~Stu(){};
    Stu(string name,int a,int c,int m,int e):
        id(name),s_a(a),s_c(c),s_m(m),s_e(e){}
    string id;
    int s_a;
    int s_c;
    int s_m;
    int s_e;
};
int main()
{
    int num_a[101]={0};
    int num_c[101]={0};
    int num_m[101]={0};
    int num_e[101]={0};
    string rank_kind="ACME";

    int N,M;
    cin>>N>>M;
    map<string,Stu>all_stu;
    for(int i=0;i<N;i++)
    {
        string name;
        int c,m,e;
        cin>>name>>c>>m>>e;
        int a=(c+m+e)/3;
        Stu t(name,a,c,m,e);
        all_stu[name]=t;
        num_a[a]++;
        num_c[c]++;
        num_m[m]++;
        num_e[e]++;
    }
    //算排名
    int sum_a=0;
    int sum_c=0;
    int sum_m=0;
    int sum_e=0;
    for(int i=100;i>=0;i--)
    {
        if(num_a[i])
        {
            int t=num_a[i];
            num_a[i]=sum_a+1;
            sum_a+=t;
        }
        if(num_c[i])
        {
            int t=num_c[i];
            num_c[i]=sum_c+1;
            sum_c+=t;
        }
        if(num_m[i])
        {
            int t=num_m[i];
            num_m[i]=sum_m+1;
            sum_m+=t;
        }
        if(num_e[i])
        {
            int t=num_e[i];
            num_e[i]=sum_e+1;
            sum_e+=t;
        }
    }

    for(int i=0;i<M;i++)
    {
        string name;
        cin>>name;
        if(all_stu.find(name)==all_stu.end())cout<<"N/A"<<endl;
        else
        {
            int rank_t[4]={0};
            rank_t[0]=num_a[all_stu[name].s_a];
            rank_t[1]=num_c[all_stu[name].s_c];
            rank_t[2]=num_m[all_stu[name].s_m];
            rank_t[3]=num_e[all_stu[name].s_e];
            int min_rank=100,min_rank_id;
            for(int j=0;j<=3;j++)
            {
                if(min_rank>rank_t[j])
                {
                    min_rank=rank_t[j];
                    min_rank_id=j;
                }
            }
            cout<<min_rank<<" "<<rank_kind[min_rank_id]<<endl;
        }
    }

    return 0;
}

我的思路: 所有数组记录所有成绩有的人数,然后从100分往下算出每个成绩对应的排名。输入一个学生,查看他四个排名,然后输出排名和类型。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GeoPandas是一个开源的Python库,旨在简化地理空间数据的处理和析。它结合了Pandas和Shapely的能力,为Python用户提供了一个强大而灵活的工具来处理地理空间数据。以下是关于GeoPandas的详细介绍: 一、GeoPandas的基本概念 1. 定义 GeoPandas是建立在Pandas和Shapely之上的一个Python库,用于处理和析地理空间数据。 它扩展了Pandas的DataFrame和Series数据结构,允许在其中存储和操作地理空间几何图形。 2. 核心数据结构 GeoDataFrame:GeoPandas的核心数据结构,是Pandas DataFrame的扩展。它包含一个或多个列,其中至少一列是几何列(geometry column),用于存储地理空间几何图形(如点、线、多边形等)。 GeoSeries:GeoPandas中的另一个重要数据结构,类似于Pandas的Series,但用于存储几何图形序列。 二、GeoPandas的功能特性 1. 读取和写入多种地理空间数据格式 GeoPandas支持读取和写入多种常见的地理空间数据格式,包括Shapefile、GeoJSON、PostGIS、KML等。这使得用户可以轻松地从各种数据源中加载地理空间数据,并将处理后的数据保存为所需的格式。 2. 地理空间几何图形的创建、编辑和析 GeoPandas允许用户创建、编辑和析地理空间几何图形,包括点、线、多边形等。它提供了丰富的空间操作函数,如缓冲区析、交集、并集、差集等,使得用户可以方便地进行地理空间数据析。 3. 数据可视化 GeoPandas内置了数据可视化功能,可以绘制地理空间数据的地图。用户可以使用matplotlib等库来进一步定制地图的样式和布局。 4. 空间连接和空间索引 GeoPandas支持空间连接操作,可以将两个GeoDataFrame按照空间关系(如相交、包含等)进行连接。此外,它还支持空间索引,可以提高地理空间数据查询的效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值