ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

1012 The Best Rank (25分) vector与结构体排序

2020-01-03 20:02:55  阅读:216  来源: 互联网

标签:25 int Rank students vector student 91 include best


1012 The Best Rank (25分)  

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


题意:给定学生的C、M、E三科成绩,求C、M、E、平均成绩A中的最好名次


#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<stack>
#include<algorithm>
#include<map>
#include<string.h>
#include<string>
#define MAX 1000000
#define ll long long
using namespace std;
struct node 
{
    int id;
    int g[4];
    int rank[4];
};
int x;//对第几门学科进行排序
bool cmp(node a,node b)
{
    return a.g[x]>b.g[x];
}

int vis[MAX];//标记学号是否存在
int main()
{
    int n,m;
    cin>>n>>m;
    vector<node>v(n);//注意是括号,n是容器大小
    memset(vis,0,sizeof(0));
    for(int i=0;i<n;i++)
    {
        cin>>v[i].id>>v[i].g[1]>>v[i].g[2]>>v[i].g[3];
        v[i].g[0]=(v[i].g[1]+v[i].g[2]+v[i].g[3])/3;
        vis[v[i].id]=1;
    }
    for(int i=0;i<4;i++)
    {
        x=i;
        sort(v.begin(),v.end(),cmp);//按照第i门学科的成绩对每个人排序
        v[0].rank[i]=1;//初始化
        for(int j=1;j<v.size();j++)
        {
            if(v[j].g[i]==v[j-1].g[i])//如果成绩相等,排名相同
                v[j].rank[i]=v[j-1].rank[i];
            else
                v[j].rank[i]=j+1;//否则排名后移一位(成绩从大到小排过序了,所以是后移)
        }
    }
    for(int i=0;i<m;i++)//m次询问
    {
        int id;
        cin>>id;
        if(vis[id]==0)
            cout<<"N/A"<<endl;
        else
        {
            int mx_rank=MAX;
            int mx_id=0;
            char s[4]={'A','C','M','E'};
            node temp;
            for(int i=0;i<v.size();i++)//查找id
            {
                if(id==v[i].id)
                {
                    temp=v[i];
                    break;
                }
            }

            for(int i=0;i<4;i++)//查找最高排名(rank数字最小)
            {
                if(temp.rank[i]<mx_rank)
                {
                    mx_rank=temp.rank[i];
                    mx_id=i;
                }
            }

            cout<<mx_rank<<' '<<s[mx_id]<<endl;
            
        }
    }
   return 0;
}

 

 

标签:25,int,Rank,students,vector,student,91,include,best
来源: https://www.cnblogs.com/-citywall123/p/12146546.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有