PAT甲级 1025 PAT Ranking

#include 
#include 
#include 
#include 
using namespace std;
typedef struct nodee
{
    char a[20];
    int grade;
    int ln;
    int lr;
    int fr;
}node;
node t[30005];
int n;
bool cmp(node p1,node p2)
{
    if(p1.grade!=p2.grade)return p1.grade>p2.grade;
    else
    {
        if (strcmp(p1.a,p2.a)>0)return false;
        else return true;
    }
}

int main()
{
    scanf("%d",&n);
    int nn = 1;
    int i =0;
    int j = 0;
    int sum = 0;
    int m;
    while (n--)
    {
        
        j = i;
        
        scanf("%d",&m);
        getchar();
        sum+=m;
        m = m+i;
        for(;i<m;i++)
        {

            scanf("%s %d",t[i].a,&t[i].grade);
            t[i].ln = nn;
        }
        sort(t+j,t+i,cmp);
        t[j].lr = 1;
        for(int count = j+1;count<i;count++)
        {
            if(t[count].grade==t[count-1].grade)t[count].lr = t[count-1].lr;
            else t[count].lr = (count-j+1);

        }
            nn++;
    }
    printf("%d\n",sum);
    sort(t,t+sum,cmp);
    t[0].fr = 1;
    for(int count= 1;count<sum;count++)
    {
        if(t[count].grade==t[count-1].grade)t[count].fr = t[count-1].fr;
        else t[count].fr = count+1;

    }
    for (int i = 0;i<sum;i++)
    {
        printf("%s %d %d %d\n",t[i].a,t[i].fr,t[i].ln,t[i].lr);
    }
    

}

你可能感兴趣的:(PAT甲级)