P1786 后五个点无法通过
查看原帖
P1786 后五个点无法通过
384592
bmyjacks楼主2020/11/4 09:03

问题

最后五个点一直WA, 找不出错误,希望大佬帮忙解答,谢谢!

代码

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const unsigned short int STRUCT_SIZE = 110 + 5;   

struct node{
    int id;
    string name;
    int zhiWei;
    long long bangGong;
    int dengJi;
}st[STRUCT_SIZE];
bool cmpBangGong(node x, node y){
    if (x.bangGong == y.bangGong){
        return x.zhiWei > y.zhiWei;
    }
    return x.bangGong > y.bangGong;
}
bool cmpZhiWei(node x, node y){
    if (x.zhiWei == y.zhiWei){
        if (x.dengJi == y.dengJi){
            return x.id < y.id;
        }
        return x.dengJi > y.dengJi;
    }
    return x.zhiWei > y.zhiWei;
}


int main(){
    unsigned short int numberOfPeople = 0;
    cin >> numberOfPeople;
    
    string nameTemp;
    int bz = 0, fbz = 0;
    for (int i = 0; i < numberOfPeople; ++i){
        st[i].id = i;
        cin >> st[i].name >> nameTemp >> st[i].bangGong >> st[i].dengJi;
        if (nameTemp == "BangZhong"){
            st[i].zhiWei = 1;
        }
        if (nameTemp == "JingYing"){
            st[i].zhiWei = 2;
        }
        if (nameTemp == "TangZhu"){
            st[i].zhiWei = 3;
        }
        if (nameTemp == "ZhangLao"){
            st[i].zhiWei = 4;
        }
        if (nameTemp == "HuFa"){
            st[i].zhiWei = 5;
        }
        if (nameTemp == "FuBangZhu"){
            st[i].zhiWei = 6;
            fbz++;
        }
        if (nameTemp == "BangZhu"){
            st[i].zhiWei = 7;
            bz++;
        }
    }
    
    sort (st, st + numberOfPeople, cmpBangGong);
    
    int hf = 0, zl = 0, tz = 0, jy = 0;
    for (int i = 0; i < numberOfPeople; ++i){
        if ((bz == 1) && (fbz == 2) && (hf == 2) && (zl == 4) && (tz == 7) && (jy == 25)) {
            st[i].zhiWei = 1;
            continue;
        }
        
        if ((st[i].zhiWei == 7) || (st[i].zhiWei == 6)){
            continue;
        }
        
        
        if (jy < 25){
            st[i].zhiWei = 2;
            jy++;
        }
        if (tz < 7){
            st[i].zhiWei = 3;
            tz++;
            jy--;
        }
        if (zl < 4){
            st[i].zhiWei = 4;
            zl++;
            tz--;
        }
        if (hf < 2){
            st[i].zhiWei = 5;
            hf++;
            zl--;
        }
        if (fbz < 2){
            st[i].zhiWei = 6;
            fbz++;
            zl--;
        }
        if (bz < 1){
            st[i].zhiWei = 7;
            bz++;
            fbz--;
        }
    }
    
    sort (st, st + numberOfPeople, cmpZhiWei);
    
    for (int i = 0; i < numberOfPeople; ++i){
        cout << st[i].name << " ";
        if (st[i].zhiWei == 1){
            cout << "BangZhong" << " ";
        }
        if (st[i].zhiWei == 2){
            cout << "JingYing" << " ";
        }
        if (st[i].zhiWei == 3){
            cout << "TangZhu" << " ";
        }
        if (st[i].zhiWei == 4){
            cout << "ZhangLao" << " ";
        }
        if (st[i].zhiWei == 5){
            cout << "HuFa" << " ";
        }
        if (st[i].zhiWei == 6){
            cout << "FuBangZhu" << " ";
        }
        if (st[i].zhiWei == 7){
            cout << "BangZhu" << " ";
        }
        cout << st[i].dengJi << endl;
    }
    cout << endl;
    
    
    return 0;
}

2020/11/4 09:03
加载中...