全网唯一最快题解,如有更快直接删帖
2026-09-13 14:16:32
发布于:广东
执行用时:20ms
内存消耗:4.75MB
击败了100.00%的用户
击败了100.00%的用户
#include <cstdio>
#include <algorithm>
using namespace std;
static char ibuf[4096];
static int ipos = 0, ilen = 0;
static inline char gc() {
if (ipos == ilen) {
ilen = (int)fread(ibuf, 1, sizeof(ibuf), stdin);
ipos = 0;
if (ilen == 0) return 0;
}
return ibuf[ipos++];
}
static inline int readInt() {
int x = 0;
char c = gc();
while (c < '0' || c > '9') c = gc();
while (c >= '0' && c <= '9') { x = x * 10 + (c - '0'); c = gc(); }
return x;
}
static char name[100005][21];
static int total[100005], gold[100005], silver[100005], ord[100005];
int main() {
int n = readInt();
for (int i = 0; i < n; i++) {
char* p = name[i];
char c = gc();
while (c <= ' ') c = gc();
while (c > ' ') { *p++ = c; c = gc(); }
p = 0;
int a = readInt(), b = readInt(), c2 = readInt();
gold[i] = a;
silver[i] = b;
total[i] = a + b + c2;
ord[i] = i;
}
sort(ord, ord + n, [](int x, int y) {
if (total[x] != total[y]) return total[x] > total[y];
if (gold[x] != gold[y]) return gold[x] > gold[y];
if (silver[x] != silver[y]) return silver[x] > silver[y];
return x < y;
});
// 输出也用手写
char obuf[1 << 16];
int opos = 0;
for (int i = 0; i < n; i++) {
int j = ord[i];
char p = name[j];
while (*p) obuf[opos++] = *p++;
obuf[opos++] = ' ';
int v = total[j];
char tmp[12]; int tl = 0;
if (v == 0) tmp[tl++] = '0';
while (v) { tmp[tl++] = '0' + v % 10; v /= 10; }
while (tl) obuf[opos++] = tmp[--tl];
obuf[opos++] = '\n';
if (opos > (1 << 15)) {
fwrite(obuf, 1, opos, stdout);
opos = 0;
}
}
if (opos) fwrite(obuf, 1, opos, stdout);
return 0;
}
全部评论 1
虽然很快,但是代码太长了
2026-09-20 来自 江苏
1这种快的代码,都是要很长的
2026-09-20 来自 广东
0











有帮助,赞一个