跳到正文

科技·工程

极其无用的 GP30 计算器

Disjoint_cat约 4 分钟
原文
文章信息与版本

文章信息

发布
2024年7月5日
收录
2025年12月12日
更新
2026年11月9日
篇幅
约 4 分钟

版本

  1. v1当前

无用的工具又要增加了(

这是一个可以模仿 AtCoder 的 GP30 分数计算并生成像这样的 KaTeX\KaTeX 表格(不含 Country/Region 和 Writer)的 C++ 工具。

Example

示例

Usage

假设有 nn 场比赛,那么前 31n31n 行为比赛数据。可以用 EOF 或 ### 作为结束符。

每场比赛的数据包含 3131 行:

  • 第一行:比赛名称
  • 第 2∼312\sim31 行:前 3030 名按顺序的用户名

得到的输出可以直接复制在任何支持 KaTeX\KaTeX 的地方即可展示。

Source

C++
//GP30 calculator by Minghan Ye ('Disjoint_cat' on luogu)
//Version 0.1

#include<bits/stdc++.h>
using namespace std;
#define PB emplace_back
#define ALL(Name) Name.begin(),Name.end()
#define VI vector<int>
#define fi first
#define se second

const int sc[]={0,100,75,60,50,45,40,36,32,29,26,24,22,20,18,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};

int main()
{
	ios::sync_with_stdio(false),cin.tie(nullptr);

	string s,ss;
	map<string,VI>mp;
	vector<string>f;
	int ds;
	for(ds=0;cin>>s;)
	{
		if(s=="###")break;
		ds++;
		ss="";
		for(char j:s)
		{
			if(j=='_')ss+="\\";
			ss+=j;
		}
		f.PB(ss);
		for(int j=1;j<=30;j++)
		{
			cin>>s;
			if(!mp.count(s))while(mp[s].size()+1<ds)mp[s].PB(0);
			mp[s].PB(sc[j]);
		}
		for(auto &j:mp)
			if(j.se.size()<ds)j.se.PB(0);
	}
	vector<tuple<int,VI,string>>v;
	for(auto i:mp)
		v.PB(-accumulate(ALL(i.se),0),i.se,i.fi);
	sort(ALL(v));
	printf("$$\n\\begin{array}{|c|c|c|");
	for(int i=1;i<=ds;i++)printf("c|");
	printf("}\\hline\\textsf{\\textbf{Place}}&\\textsf{\\textbf{Handle}}&\\textsf{\\textbf{Score}}");
	for(auto i:f)printf("&\\textsf{\\textbf{%s}}",i.c_str());
	int plc=0,cplc=0,lst=114514;
	for(auto i:v)
	{
		int tot;VI d;string name,conv;
		tie(tot,d,name)=i;
		for(char j:name)
		{
			if(j=='_')conv+="\\";
			conv+=j;
		}
		cplc++;
		if(lst!=tot)lst=tot,plc=cplc;
		printf("\\\\\\hline%d&\\texttt{%s}&%d",plc,conv.c_str(),-tot);
		for(int j:d)
		{
			printf("&");
			if(j)printf("%d",j);
		}
	}
	printf("\\\\\\hline\\end{array}\n$$");

	return 0;
}
原文