跳到正文

个人记录

小工具

kqpkao约 19 分钟
原文
文章信息与版本

文章信息

发布
2024年10月19日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 19 分钟

版本

  1. v1当前

数据生成器

C++
// gen
#include <ctime>
#include <cstdio>
#include <random>
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
mt19937 rd(time(nullptr) ^ 2138947);
const int CRSS = 36;// char random set size
const int CRS[200] = {
	0, /*total*/
	0,   /*0*/ 0,   /*1*/ 0,   /*2*/
	0,   /*3*/ 0,   /*4*/ 0,   /*5*/
	0,   /*6*/ 0,   /*7*/ 0,   /*8*/
	0,   /*9*/ 0,   /*a*/ 0,   /*b*/
	0,   /*c*/ 0,   /*d*/ 0,   /*e*/
	0,   /*f*/ 0,   /*g*/ 0,   /*h*/
	0,   /*i*/ 0,   /*j*/ 0,   /*k*/
	0,   /*l*/ 0,   /*m*/ 0,   /*n*/
	0,   /*o*/ 0,   /*p*/ 0,   /*q*/
	0,   /*r*/ 0,   /*s*/ 0,   /*t*/
	0,   /*u*/ 0,   /*v*/ 0,   /*w*/
	0,   /*x*/ 0,   /*y*/ 0,   /*z*/
};// char random set
int randint(int randint_b, int randint_e);// random number in [b, e](save by "int")
ll randll(ll randll_b, ll randll_e);// random number in [b, e](save by "long long int")
char inttochar(int idx);
char randchar();// random char in "char set"
void write(ll write_x);// quick write ( It can use types "int" and "long long".)
void show();// output the data
// =====================================================================
// define variables

int main(){
	
	show();
	return 0;
}
void show(){
	
	return;
}
// The following doesn't need changes
// =====================================================================
int randint(int randint_b, int randint_e){
	int rand_int = rd() % randint_e;
	rand_int = (rand_int * rd()) % randint_e;
	return (rand_int % (randint_e - randint_b + 1)) + randint_b;
}
ll randll(ll randll_b, ll randll_e){
	ll rand_long = rd() % randint_e;
	rand_long = (rand_long * rd()) % randint_e;
	rand_long = (rand_long * rd()) % randint_e;
	rand_long = (rand_long * rd()) % randint_e;
	return (rand_long % (randll_e - randll_b + 1)) + randll_b;
}
char inttochar(int idx){
	if (idx <= 10){
		return (char)(idx - 1 + '0');
	}
	return (char)(idx - 11 + 'a');
}
char randchar(){
	int x = randint(1, CRS[0]);
	int pts = 0;
	for (int i = 1; i <= CRSS; i++){
		if (pts <= x && x <= pts + CRS[i]){
			return inttochar(i);
		}
		pts += CRS[i];
	}
	return ('\0');
}
void write(ll write_x){
	if (write_x < 0){
		putchar('-');
		write_x = -write_x;
	}
	if (write_x > 9){
		write(write_x / 10);
	}
	putchar(write_x % 10 | 48);
	return;
}

自动对拍

空出的文件名前要填补相同内容。

C++
// pppp
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
	for (int t = 1; ; ++t){
		printf("== test : %d ==\n", t);
		system("gen.exe > .in");
		system(".exe < .in > .out");
		system("stdstd.exe < .in > stdstd.out");
		if (system("fc .out stdstd.out")){
			system("pause");
		}
		if (t % 10 == 0){
			system("cls");
		}
	}
	return 0;
}

造数据自动机

C++
// create
#include <ctime>
#include <string>
#include <cstdlib>
#include <windows.h>
using namespace std;
const int dataIDBegin = ..., dataIDEnd = ...;
const int orderLen = 2e3 + 5;
const string fileName = "...";
string fileID, fileIn, fileOut;
char systemOrder[orderLen];
void systemRun(string stringOrder){
	int len = (int)(stringOrder.length());
	for (int i = 0; i < len; ++i){
		systemOrder[i] = stringOrder[i];
	}
	systemOrder[len] = '\0';
	system(systemOrder);
	return;
}
int main(){
	srand(time(0) ^ 114514);
	for (int i = dataIDBegin; i <= dataIDEnd; ++i){
		fileID = to_string(i);
		fileIn = fileName + fileID + ".in";
		systemRun("gen.exe > " + fileIn);
		fileOut = fileName + fileID + ".out";
		systemRun("stdstd.exe < " + fileIn + " > " + fileOut);
		Sleep(rand() % 1450 + 1050);
	}
	return 0;
}

SPJ

C++
//
#include <cstdio>
using namespace std;
int judgeResult;/*
judge results stand for states:
| judgeResult |      states      |
|      1      |   AC(Accepted)   |
|   * other   | WA(Wrong Answer) |
This SPJ's result isn't have RE, TLE, MLE and UKE.

* [other] : A number greater than one.

*/
const int N = 5e2 + 5;
int n, p[N], q[N], ans[N][N];
void judge(){
	return;
}// 评测 
int main(){
	printf("\nInput the input data:\n\n");
   // 输入代码的输入数据 
	printf("\nInput the program's output data:\n\n");
   // 输入代码的输出数据 
	printf("\nJudging...\n\n");
	judge();// 评测 
	if (judgeResult == 1){
		printf("== AC(Accepted) ==\n");
	}
	if (judgeResult > 1){
		printf("== WA(Wrong Answer) ==\n");
		// 输出报错信息 
	}
	return 0;
}

递归函数监视器

C++
struct Function_print{
	int tab, step;
	void pt(){
		for (int i = 1; i <= tab; i++){
			for (int j = 1; j <= step; j++){
				printf(" ");
			}
		}
		return;
	}
	void push(){
		for (int i = 1; i <= tab; i++){
			for (int j = 1; j <= step; j++){
				printf(" ");
			}
		}
		printf("(){\n");
		tab++;
		return;
	}
	void pop(){
		for (int i = 1; i <= tab; i++){
			for (int j = 1; j <= step; j++){
				printf(" ");
			}
		}
		printf("return \n");
		tab--;
		for (int i = 1; i <= tab; i++){
			for (int j = 1; j <= step; j++){
				printf(" ");
			}
		}
		printf("}\n");
		return;
	}
	void Return(){
		for (int i = 1; i <= tab; i++){
			for (int j = 1; j <= step; j++){
				printf(" ");
			}
		}
		printf("return to ()\n");
		return;
	}
	void newstep(int ns){
		step = ns;
		return;
	}
	void clear(){
		tab = 0;
		return;
	}
};

质数判断

C++
// check prime
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
ll x, k;
int main(){
	while (scanf("%lld", &x) != EOF){
		if (x < 0){
			system("cls");
			continue;
		}
		if (x <= 1){
			printf("This isn't a prime.\n");
			continue;
		}
		for (ll i = 2; i * i <= x; ++i){
			if (x % i == 0){
				k = i;
				break;
			}
		}
		if (k){
			printf("This isn't a prime.\n");
			printf("%lld = %lld * %lld\n", x, k, x / k);
			k = 0;
		}
		else{
			printf("This is a prime.\n");
		}
	}
	return 0;
}
/*
100003    (1e5 + 3)
1000003   (1e6 + 3)
998244353
1000000007 (1e9 + 7)
*/

质数生成器

C++
// create prime
#include <ctime>
#include <cstdio>
#include <random>
#include <cstdlib>
using namespace std;
typedef long long ll;
mt19937 rd(time(nullptr));
ll L, R;
int cnt;
bool isPrime(ll x){
	if (x <= 1){
		return false;
	}
	for (ll i = 2; i * i <= x; i++){
		if (x % i == 0){
			return false;
		}
	}
	return true;
}
int main(){
	while (true){
		scanf("%lld%lld", &L, &R);
		if (L < 0 || R < 0){
			system("cls");
			continue;
		}
		if (L == 0 || R == 0){
			break;
		}
		scanf("%d", &cnt);
		printf("\n=====\n\n");
		while (cnt--){
			ll now = 0;
			do{
				now = ((rd() << 10) ^ rd()) % (R - L + 1) + L;
			}while (!isPrime(now));
			printf("%lld\n", now);
		}
		printf("\n=====\n");
	}
	return 0;
}
/*
100003    (1e5 + 3)
1000003   (1e6 + 3)
998244353
1000000007 (1e9 + 7)
*/

计时器

C++
// my clock
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
using namespace std;
int Thour, Tminute, Tsecond;
long long Time;
double last;
inline void HideCursor(){
	CONSOLE_CURSOR_INFO cur={1,0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
inline void Place(const int x, const int y){
	COORD PlaceCursorHere;
	PlaceCursorHere.X = x;
	PlaceCursorHere.Y = y;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), PlaceCursorHere);
	return;
}
inline void showTime(){
	if (!Tsecond){
		Tsecond = 60;
		if (!Tminute){
			Tminute = 60;
			Place(2, 1);printf("%02d", --Thour);
		}
		Place(5, 1);printf("%02d", --Tminute);
	}
	Place(8, 1);printf("%02d", --Tsecond);
	return;
}
int main(){
	printf("  hours : ");
	scanf("%d", &Thour);
	printf("minutes : ");
	scanf("%d", &Tminute);
	printf("seconds : ");
	scanf("%d", &Tsecond);
	system("cls");
	printf("\n  %02d:%02d:%02d", Thour, Tminute, Tsecond);
	last = (double)(clock());
	while (Thour || Tminute || Tsecond){
		while (((double)(clock()) - last) / CLOCKS_PER_SEC < 0.999);
		showTime();
		last = (double)(clock());
	}
	system("cls");
	printf("\n  done!\n");
    HWND hwnd=GetForegroundWindow();
	MessageBox(hwnd,"Timing ended.","Note",MB_OK);
	return 0;
}

题目排序机

C++
/*
The index stand for seven types.
In the following, I used seven
letters to replace types prefix.
Index 0 stand for the "P".
Index 1 stand for the "B".
Index 2 stand for the "C".
Index 3 stand for the "S".
Index 4 stand for the "A".
Index 5 stand for the "U".
Index 6 stand for the "T".

Input prompt: Type ^ Z to end input
*/
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const char problem_id_prefix[7] = {'P', 'B', 'C', 'S', 'A', 'U', 'T'};
struct problem{
	string ID;
	int difficulty;
};
problem newProblem;
vector<problem> problems[7];
int prefix_map_to_index(char prefix){
	for (int i = 0; i < 7; i++){
		if (prefix == problem_id_prefix[i]){
			return i;
		}
	}
	return -1;
}
bool cmp(problem x, problem y){
	if (x.difficulty == y.difficulty){
		return x.ID < y.ID;
	}
	return x.difficulty < y.difficulty;
}//Can change it.
void display(int Type){
	cout << problem_id_prefix[Type] << "\n\n";
	for (int i = 0; i < (int)(problems[Type].size()); i++){
		cout << "> " << problems[Type][i].ID << '\n';
	}
	cout << '\n';
	return;
}
int main(){
	while (cin >> newProblem.ID >> newProblem.difficulty){
		int Index = prefix_map_to_index(newProblem.ID[0]);
		if (Index == -1){
			cout << "This problem is invalid.\n";
			continue;
		}
		problems[Index].push_back(newProblem);
	}
	for (int i = 0; i < 7; i++){
		if (problems[i].size() > 0){
			sort(problems[i].begin(), problems[i].end(), cmp);
			display(i);
		}
	}
	return 0;
}

end

蒟蒻的其他专栏。

不要在意这个专栏的链接。

原文