【代码求调】今天真的是恶心死我啦
查看原帖
【代码求调】今天真的是恶心死我啦
206814
封禁用户楼主2023/1/19 19:31

今天我们考试考了这个东西。。。

太难写啦啊喂!

#include <cstdio>
#include <iostream>
using namespace std;
struct Student{
    long long id;
    bool sex; //true: male, false: female
    int special_score;
    struct Time{
        int minute;
        int second;
    }long_score;
    bool mess;
    int final_score;
    int camping;
    int runtimes;
    int answer;
    string kpi;
    struct Record{
        struct Date{
            int year;
            int month;
            int day;
            bool operator==(Date b){
                return (this->year == b.year) && (this->month == b.month) && (this->day == b.day);
            }
            bool operator<(Date b){
                if(this->year == b.year){
                    if(this->month == b.month){
                        return this->day < b.day;
                    }
                    return this->month < b.month;
                }
                return this->year < b.year;
            }
        }end_date;
        long long from_id;
        struct Time{
            int hour = 0;
            int minute;
            int second;
            bool operator==(Time b){
                return (this->hour == b.hour) && (this->minute == b.minute) && (this->second == b.second);
            }
            bool operator<(Time b){
                if(this->hour == b.hour){
                    if(this->minute == b.minute){
                        return this->second < b.second;
                    }
                    return this->minute < b.minute;
                }
                return this->hour < b.hour;
            }
            bool operator>(Time b){
                return !(*this == b) && !(*this < b);
            }
        }start, end, pause;
        double dist;
        int steps;
    };
    vector<Record> records;
}students[10005];
unordered_map<long long, Student*> findStudent;
int main(){
#ifndef LOCAL
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
#endif
    int n, m;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> students[i].id;
        char ch; cin >> ch; students[i].sex = (ch == 'M');
        cin >> students[i].special_score;
        scanf("%d'%d\"", &students[i].long_score.minute, &students[i].long_score.second);
        cin >> ch; students[i].mess = (ch == 'P');
        cin >> students[i].final_score >> students[i].camping;
        findStudent[students[i].id] = &students[i];
    }
    cin >> m;
    for(int i = 1, id; i <= m; i++){
        string str;
        cin >> str;
        cin >> id;
        findStudent[id]->records.push_back(Student::Record());
        findStudent[id]->records.back().from_id = id;
        findStudent[id]->records.back().end_date.year = stoi(str.substr(0, 4));
        findStudent[id]->records.back().end_date.month = stoi(str.substr(4, 2));
        findStudent[id]->records.back().end_date.day = stoi(str.substr(6, 2));
        cin >> str;
        findStudent[id]->records.back().start.hour = stoi(str.substr(0, 2));
        findStudent[id]->records.back().start.minute = stoi(str.substr(3, 2));
        findStudent[id]->records.back().start.second = stoi(str.substr(6, 2));
        cin >> str;
        findStudent[id]->records.back().end.hour = stoi(str.substr(0, 2));
        findStudent[id]->records.back().end.minute = stoi(str.substr(3, 2));
        findStudent[id]->records.back().end.second = stoi(str.substr(6, 2));
        cin >> findStudent[id]->records.back().dist;
        scanf("%d'%d\"", &findStudent[id]->records.back().pause.minute, &findStudent[id]->records.back().pause.second);
        cin >> findStudent[id]->records.back().steps;
    }
    for(int i = 1; i <= n; i++){
        students[i].answer += students[i].special_score;
        int Time = students[i].long_score.minute * 60 + students[i].long_score.second;
        if(students[i].sex){
            if(Time <= 750) students[i].answer += 20;
            else if(Time > 750 && Time <= 780) students[i].answer += 18;
            else if(Time > 780 && Time <= 810) students[i].answer += 16;
            else if(Time > 810 && Time <= 840) students[i].answer += 14;
            else if(Time > 840 && Time <= 870) students[i].answer += 12;
            else if(Time > 870 && Time <= 910) students[i].answer += 10;
            else if(Time > 910 && Time <= 950) students[i].answer += 8;
            else if(Time > 950 && Time <= 990) students[i].answer += 6;
            else if(Time > 990 && Time <= 1030) students[i].answer += 4;
            else if(Time > 1030 && Time <= 1080) students[i].answer += 2;
        }else{
            if(Time <= 400) students[i].answer += 20;
            else if(Time > 400 && Time <= 417) students[i].answer += 18;
            else if(Time > 417 && Time <= 434) students[i].answer += 16;
            else if(Time > 434 && Time <= 451) students[i].answer += 14;
            else if(Time > 451 && Time <= 470) students[i].answer += 12;
            else if(Time > 470 && Time <= 485) students[i].answer += 10;
            else if(Time > 485 && Time <= 500) students[i].answer += 8;
            else if(Time > 500 && Time <= 515) students[i].answer += 6;
            else if(Time > 515 && Time <= 530) students[i].answer += 4;
            else if(Time > 530 && Time <= 540) students[i].answer += 2;
        }
    }
    auto getSeconds = [](Student::Record::Time a)->int{
        return a.hour * 3600 + a.minute * 60 + a.second;
    };
    const int days[17] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    for(int index = 1; index <= n; index++){
        sort(students[index].records.begin(), students[index].records.end(), [](Student::Record a, Student::Record b)->bool{
            if(a.end_date == b.end_date){
                return a.start < b.start;
            }
            return a.end_date < b.end_date;
        });
        for(int i = 0; i < students[i].records.size(); i++){
            int endSeconds = getSeconds(students[index].records[i].end), startSeconds = getSeconds(students[index].records[i].start);
            double v = students[index].records[i].dist / (endSeconds - startSeconds);
            if(students[index].sex && students[index].records[i].dist < 3000) continue;
            if(!students[index].sex && students[index].records[i].dist < 1500) continue;
            if(v < 2 || v > 5) continue;
            if(students[index].records[i].pause.minute * 60 + students[index].records[i].pause.second > 270) continue;
            if(students[index].records[i].dist / students[index].records[i].steps > 1.5) continue;
            if(i != 1){
                if(students[index].records[i].end_date.month - students[index].records[i - 1].end_date.month > 1) goto OK;
                int _endSeconds = getSeconds(students[index].records[i - 1].end), _startSeconds = getSeconds(students[index].records[i - 1].start);
                if(students[index].records[i - 1].end_date.day == days[students[index].records[i - 1].end_date.month] && students[index].records[i].end_date.day == days[students[index].records[i].end_date.day]){
                    if(86400 + _endSeconds - startSeconds > 21600) 
                        goto OK;
                } 
                if(students[index].records[i].end_date.day - students[index].records[i - 1].end_date.day > 1) goto OK;
                else if(students[index].records[i].end_date.day - students[index].records[i - 1].end_date.day == 1){
                    if(86400 + _endSeconds - startSeconds > 21600)
                        goto OK;
                }else{
                    if(_endSeconds - startSeconds > 21600)
                        goto OK;
                }
                goto Fail;
            }
            OK: students[index].runtimes++;
            Fail:;
        }
    }
    for(int i = 1; i <= n; i++){
        if(students[i].runtimes >= 3 && students[i].runtimes <= 6) students[i].answer += 2;
        if(students[i].runtimes >= 7 && students[i].runtimes <= 10) students[i].answer += 4;
        if(students[i].runtimes >= 11 && students[i].runtimes <= 13) students[i].answer += 6;
        if(students[i].runtimes >= 14 && students[i].runtimes <= 16) students[i].answer += 7;
        if(students[i].runtimes >= 17 && students[i].runtimes <= 18) students[i].answer += 8;
        if(students[i].runtimes >= 19 && students[i].runtimes <= 20) students[i].answer += 9;
        if(students[i].runtimes >= 21) students[i].answer += 10;
        if(students[i].mess) students[i].answer += 10;
        int outgoing = students[i].camping + students[i].runtimes;
        if(outgoing >= 6 && outgoing <= 8) students[i].answer += 1;
        if(outgoing >= 9 && outgoing <= 11) students[i].answer += 2;
        if(outgoing >= 12 && outgoing <= 14) students[i].answer += 3;
        if(outgoing >= 15 && outgoing <= 17) students[i].answer += 4;
        if(outgoing >= 18) students[i].answer += 5;
        students[i].answer += students[i].final_score;
        if(students[i].answer >= 0 && students[i].answer < 60) students[i].kpi = "F";
        if(students[i].answer >= 60 && students[i].answer < 63) students[i].kpi = "D";
        if(students[i].answer >= 63 && students[i].answer < 67) students[i].kpi = "D+";
        if(students[i].answer >= 67 && students[i].answer < 70) students[i].kpi = "C-";
        if(students[i].answer >= 70 && students[i].answer < 73) students[i].kpi = "C";
        if(students[i].answer >= 73 && students[i].answer < 77) students[i].kpi = "C+";
        if(students[i].answer >= 77 && students[i].answer < 80) students[i].kpi = "B-";
        if(students[i].answer >= 80 && students[i].answer < 85) students[i].kpi = "B";
        if(students[i].answer >= 85 && students[i].answer < 90) students[i].kpi = "B+";
        if(students[i].answer >= 90 && students[i].answer < 95) students[i].kpi = "A-";
        if(students[i].answer >= 95 && students[i].answer <= 100) students[i].kpi = "A";
        cout << students[i].id << ' ' << students[i].answer << ' ' << students[i].kpi << endl;
    }
    return 0;
}
2023/1/19 19:31
加载中...