PAT (Advanced Level) 1025 PAT Ranking

题解

模拟水题。

代码

#include<bits/stdc++.h>
using namespace std;
struct node
{
    string name;
    int final_rank,loc_num,loc_rank,grade;
    node(string name,int loc_num,int grade)
    {
      this->name=name;
      this->loc_num=loc_num;
      this->grade=grade;
    }
    void paixu(int flag,int w)
    {
       flag==0?loc_rank=w:final_rank=w;
    }
    bool operator <(const node &n) const
    {
        if(grade!=n.grade)
            return grade>n.grade;
        else
            return name<n.name;
    }
};
vector<node> v;
int k;
void paixu(int s,int e,int flag);
int main()
{
    int i,j,n,grade,start=0;
    string name;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&k);
        for(j=0;j<k;j++)
        {
            cin>>name>>grade;
            v.push_back(node(name,i,grade));
        }
        sort(v.begin()+start,v.begin()+start+k);
        paixu(start,start+k,0);
        start+=k;
    }

    sort(v.begin(),v.end());
    paixu(0,v.size(),1);

    printf("%d\n",v.size());
    for(i=0;i<v.size();i++)
        printf("%s %d %d %d\n",v[i].name.c_str(),v[i].final_rank,v[i].loc_num,v[i].loc_rank);
    system("pause");
    return 0;
}
void paixu(int s,int e,int flag)
{
    int i,pre_grade=-1,cnt=1,same=1;
    for(i=s;i<e;i++)
    {
        if(v[i].grade!=pre_grade)
        {
            v[i].paixu(flag,cnt);
            same=cnt;
        }
        else
        {
            v[i].paixu(flag,same);
        }
        cnt++;
        pre_grade=v[i].grade;
    }
}

原文地址:https://www.cnblogs.com/VividBinGo/p/12221298.html

时间: 2024-10-02 11:47:20

PAT (Advanced Level) 1025 PAT Ranking的相关文章

PAT (Advanced Level) 1025. PAT Ranking (25)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<string> #include<vector> using namespace std; const int maxn=110; int n,tot=0; int sz[m

PTA(Advanced Level)1025.PAT Ranking

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 e

PAT (Advanced Level) 1075. PAT Judge (25)

简单模拟题. 注意一点:如果一个人所有提交的代码都没编译通过,那么这个人不计排名. 如果一个人提交过的代码中有编译不通过的,也有通过的,那么那份编译不通过的记为0分. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<str

PAT (Advanced Level) 1075 PAT Judge

题解 模拟. 题目有三种状态. 第一种为题目得到了一定的分数( >= 0): 第二种为题目提交过但是没有通过编译(代码中状态为 -2 ,输出对应 0 ): 第三种题目根本就没提交过(代码中状态为 -1 ,输出对应 ‘-’ ). 考生只要至少有一道题目满足第一种情况,即可将这位考生的信息输出出来. 代码 #include<bits/stdc++.h> using namespace std; int N,K,M,score[6]; struct node { int name,grade[

Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)

Pat1043代码 题目描述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes

Pat(Advanced Level)Practice--1044(Shopping in Mars)

Pat1044代码 题目描述: Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diam

PAT (Advanced Level) 1093. Count PAT&#39;s (25)

预处理每个位置之前有多少个P,每个位置之后有多少个T. 对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数. #include<cstdio> #include<cstring> long long MOD=1e9+7; const int maxn=1e5+10; long long dp1[maxn],dp2[maxn]; char s[maxn]; int main() { scanf("%s",s); memset(dp1,0,sizeof d

PAT (Advanced Level) 1055. The World&#39;s Richest (25)

排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using names

Pat(Advanced Level)Practice--1018(Public Bike Management)

Pat1018代码 题目描述: There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city. The Public Bike Management C