其他分享
首页 > 其他分享> > 【PAT A1025】部分正确->全部正确

【PAT A1025】部分正确->全部正确

作者:互联网

#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <cstring>
#include <vector>
using namespace std;
#define maxN 105
#define manK 305
#define manS 30010

struct Stu {
    char regist[16];
    int socre;
    int finalRank;
    int locationNumber;
    int localRank;
    Stu() {}
    Stu(char _regist[], int _socre, int _locationNumber) {
        strcpy(this->regist,_regist);
        this->socre =_socre;
        this->locationNumber = _locationNumber;
    }
}static students[manS];

static int N;
static int K;
static int numS;

bool cmp(Stu stu1, Stu stu2) {
    if(stu1.socre != stu2.socre) return stu1.socre > stu2.socre;
    else return strcmp(stu1.regist,stu2.regist) < 0;
}

void groupSort(int K) {
    sort(students + (numS-K), students + numS, cmp);
    Stu *stu = students + (numS-K);
    stu->localRank = 1;
    for (int i = 1; i < K; i++) {
        Stu* preStu = students + (numS-K+i-1);
        Stu* stu = students + (numS-K+i);
        if(stu->socre == preStu->socre) stu->localRank = preStu->localRank;
        else stu->localRank = i+1;
    }
    return;
}

void fileInput() {
    ifstream fin;
    fin.open("/home/zzz/input.txt",ios::in);
    fin >> N;
    numS = 0;
    for (int i = 0; i < N; i++) {
        fin >> K;
        for (int j = 0; j < K; j++) {
            char _regist[16];
            int _score;
            fin >> _regist >> _score;
            students[numS] = Stu(_regist, _score, i+1);
            numS++;
        }
        groupSort(K);
    }
    return;
}

void stdInput() {
    cin >> N;
    numS = 0;
    for (int i = 0; i < N; i++) {
        cin >> K;
        for (int j = 0; j < K; j++) {
            char _regist[16];
            int _score;
            cin >> _regist >> _score;
            students[numS] = Stu(_regist, _score, i + 1);
            numS++;
        }
        groupSort(K);
    }
    return;
}

int main() {
    stdInput();
    cout << numS << endl;
    sort(students, students + numS, cmp);
    Stu* stu = students;
    stu->finalRank = 1;
    printf("%s %d %d %d\n", stu->regist, stu->finalRank, stu->locationNumber, stu->localRank);
    for (int i = 1; i < numS; i++) {
        Stu* stu = students + i;
        Stu* preStu = students + i - 1;
        if(stu->socre == preStu->socre) stu->finalRank = preStu->finalRank;
        else stu->finalRank = i+1;
        printf("%s %d %d %d\n", stu->regist, stu->finalRank, stu->locationNumber, stu->localRank);
    }
    return 0;
}

我把manS放到30005部分正确,把它开到30010即全部正确、、、见了贵了

刷题感悟:

标签:PAT,正确,numS,int,regist,Stu,A1025,stu,socre
来源: https://www.cnblogs.com/huangming-zzz/p/11673487.html