WA on #4求助
  • 板块CF2A Winner
  • 楼主zzyxl_qaq
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/2 16:15
  • 上次更新2023/11/3 06:20:22
查看原帖
WA on #4求助
386921
zzyxl_qaq楼主2023/8/2 16:15
#include <bits/stdc++.h>
using namespace std;
struct node {
    string name;
    int pts, rndx;
}a[1005];
bool cmp (node a, node b) {
    if (a.pts != b.pts) return a.pts > b.pts;
    else return a.rndx < b.rndx;
}
int pos;
int main () {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++ i) {
        string nname;
        int npts;
        cin >> nname >> npts;
        bool ok = true;
        for (int j = 1; j <= pos; ++ j) {
            if (a[pos].name == nname) {
                a[pos].pts += npts;
                a[pos].rndx = i;
                ok = false;
            }
        }
        if (ok) {
            a[++ pos].name = nname;
            a[pos].pts = npts;
            a[pos].rndx = i;
        }
    }
    sort (a + 1, a + pos + 1, cmp);
    cout << a[1].name;
}
2023/8/2 16:15
加载中...