开o2优化就全wa,不开就过了,求解
查看原帖
开o2优化就全wa,不开就过了,求解
430715
accereator楼主2024/10/22 23:20
#include<bits/stdc++.h>
using namespace std;
int n;
struct P1786
{
    string name;
    string po;
    long long ba;
    int lv; 
    int num;
}a[1000];

bool cmp(P1786 x,P1786 y)
{
    if(x.ba!=y.ba)
        return x.ba>y.ba;
    else
        return x.num<y.num;
}

int zhuan(string x)
{
    int x1;
    if(x=="BangZhu") x1=1;
    else if (x=="FuBangZhu") x1=2;
    else if (x=="HuFa") x1=3;
    else if (x=="ZhangLao") x1=4;
    else if (x=="TangZhu") x1=5;
    else if (x=="JingYing") x1=6;
    else  x1=7;
    return x1;

}
bool cmp1(P1786 x,P1786 y)
{
    if(zhuan(x.po)!=zhuan(y.po))
        return zhuan(x.po)<zhuan(y.po);
    else if(x.lv!=y.lv)
        return x.lv>y.lv;
    else
        return x.num<y.num;
}

string p[1000];



void open()
{
    for(int i=0;i<=1000;i++)
    {
        if (i<2)
        {
            p[i]="HuFa";
        }
        else if (i<6)
        {
            p[i]="ZhangLao";
        }
        else if (i<13)
        {
            p[i]="TangZhu";
        }
        else if (i<38)
        {
            p[i]="JingYing";
        }
        else 
        {
            p[i]="BangZhong";
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i].name>>a[i].po>>a[i].ba>>a[i].lv;
        a[i].num=i;
        if(a[i].po!="BangZhu"&&a[i].po!="FuBangZhu")
        {
            a[i].po.clear();
        }
    }
    sort(a,a+n,cmp);
    open();
    int o=0;
    for (int i = 0; i < n; i++)
    {
        if (a[i].po.length()==0)
            a[i].po=p[o++];
    }
    sort(a,a+n,cmp1);
    for (int i = 0; i < n; i++)
    {
        cout<<a[i].name<<' '<<a[i].po<<' '<<a[i].lv<<endl;
    }
    return 0;
}

2024/10/22 23:20
加载中...