oimp
Version:
A CLI tool for generating OI problem and packages
1,162 lines (991 loc) • 36.2 kB
JavaScript
// C++ 标准库补全定义 - 适用于 Monaco Editor
// 这个文件提供了C++标准库的基本类型和函数定义,用于代码补全
export const cppStd =
`// 完整的 C++ 标准库类型定义(模拟)
// 覆盖 C++11 及以上核心组件,用于代码补全提示
declare namespace std {
// 基础类型与常量
type size_t = number;
type ptrdiff_t = number;
type int8_t = number;
type int16_t = number;
type int32_t = number;
type int64_t = number;
type uint8_t = number;
type uint16_t = number;
type uint32_t = number;
type uint64_t = number;
type float_t = number;
type double_t = number;
type nullptr_t = null;
const NAN: number;
const INFINITY: number;
const M_PI: number;
const M_E: number;
// 类型特性(type_traits 简化版)
namespace type_traits {
type true_type = { value: true };
type false_type = { value: false };
type is_integral<T> = T extends number ? true_type : false_type;
type is_floating_point<T> = T extends number ? true_type : false_type;
type remove_reference<T> = T;
type add_pointer<T> = () => T;
}
// 输入输出流(扩展版)
namespace io {
// 操纵符
function endl(stream: OutputStream): OutputStream;
function ends(stream: OutputStream): OutputStream;
function flush(stream: OutputStream): OutputStream;
function hex(stream: OutputStream): OutputStream;
function dec(stream: OutputStream): OutputStream;
function oct(stream: OutputStream): OutputStream;
interface OutputStream {
operator<<(value: string): OutputStream;
operator<<(value: number): OutputStream;
operator<<(value: boolean): OutputStream;
operator<<(value: nullptr_t): OutputStream;
operator<<(manipulator: (s: OutputStream) => OutputStream): OutputStream;
put(c: string): OutputStream;
write(buffer: string, count: size_t): OutputStream;
flush(): OutputStream;
width(w: size_t): size_t;
precision(p: size_t): size_t;
fill(c: string): string;
good(): boolean;
eof(): boolean;
fail(): boolean;
bad(): boolean;
clear(flags?: number): void;
}
interface InputStream {
operator>>(value: number): InputStream;
operator>>(value: string): InputStream;
operator>>(value: boolean): InputStream;
operator>>(manipulator: (s: InputStream) => InputStream): InputStream;
get(): string;
getline(str: string, delim: string = '\n'): InputStream;
read(buffer: string, count: size_t): InputStream;
gcount(): size_t;
ignore(n: size_t = 1, delim: string = '\n'): InputStream;
peek(): string;
unget(): InputStream;
good(): boolean;
eof(): boolean;
fail(): boolean;
bad(): boolean;
clear(flags?: number): void;
}
const cout: OutputStream;
const cin: InputStream;
const cerr: OutputStream;
const clog: OutputStream;
}
// 字符串(扩展版)
class string {
constructor();
constructor(size: size_t, c: string);
constructor(str: string);
constructor(str: string, pos: size_t, len: size_t = npos);
constructor(first: iterator<string>, last: iterator<string>);
static npos: size_t;
length(): size_t;
size(): size_t;
max_size(): size_t;
capacity(): size_t;
empty(): boolean;
reserve(n: size_t): void;
resize(n: size_t, c: string = '\0'): void;
clear(): void;
operator[](pos: size_t): string;
at(pos: size_t): string;
front(): string;
back(): string;
data(): string;
c_str(): string;
operator+(str: string): string;
operator+(c: string): string;
operator+=(str: string): string;
operator+=(c: string): string;
operator==(str: string): boolean;
operator!=(str: string): boolean;
operator<(str: string): boolean;
operator>(str: string): boolean;
operator<=(str: string): boolean;
operator>=(str: string): boolean;
assign(str: string): string;
assign(str: string, pos: size_t, len: size_t): string;
assign(count: size_t, c: string): string;
assign(first: iterator<string>, last: iterator<string>): string;
append(str: string): string;
append(str: string, pos: size_t, len: size_t): string;
append(count: size_t, c: string): string;
append(first: iterator<string>, last: iterator<string>): string;
push_back(c: string): void;
pop_back(): void;
insert(pos: size_t, str: string): string;
insert(pos: size_t, str: string, subpos: size_t, sublen: size_t): string;
insert(pos: size_t, count: size_t, c: string): string;
insert(pos: iterator<string>, count: size_t, c: string): iterator<string>;
erase(pos: size_t, len: size_t = npos): string;
erase(pos: iterator<string>): iterator<string>;
erase(first: iterator<string>, last: iterator<string>): iterator<string>;
replace(pos: size_t, len: size_t, str: string): string;
replace(first: iterator<string>, last: iterator<string>, str: string): string;
find(str: string, pos: size_t = 0): size_t;
find(c: string, pos: size_t = 0): size_t;
rfind(str: string, pos: size_t = npos): size_t;
find_first_of(str: string, pos: size_t = 0): size_t;
find_last_of(str: string, pos: size_t = npos): size_t;
find_first_not_of(str: string, pos: size_t = 0): size_t;
find_last_not_of(str: string, pos: size_t = npos): size_t;
substr(pos: size_t = 0, len: size_t = npos): string;
compare(str: string): number;
compare(pos: size_t, len: size_t, str: string): number;
}
// 迭代器
interface iterator<T> {
operator*(): T;
operator->(): T;
operator++(): iterator<T>;
operator++(n: number): iterator<T>;
operator--(): iterator<T>;
operator--(n: number): iterator<T>;
operator+(n: number): iterator<T>;
operator-(n: number): iterator<T>;
operator+=(n: number): iterator<T>;
operator-=(n: number): iterator<T>;
operator==(other: iterator<T>): boolean;
operator!=(other: iterator<T>): boolean;
operator<(other: iterator<T>): boolean;
operator>(other: iterator<T>): boolean;
}
interface reverse_iterator<T> {
operator*(): T;
operator->(): T;
operator++(): reverse_iterator<T>;
operator++(n: number): reverse_iterator<T>;
operator--(): reverse_iterator<T>;
operator--(n: number): reverse_iterator<T>;
operator==(other: reverse_iterator<T>): boolean;
operator!=(other: reverse_iterator<T>): boolean;
}
// 容器:顺序容器
class vector<T> {
constructor();
constructor(size: size_t);
constructor(size: size_t, value: T);
constructor(elements: T[]);
constructor(first: iterator<T>, last: iterator<T>);
size(): size_t;
capacity(): size_t;
max_size(): size_t;
empty(): boolean;
reserve(n: size_t): void;
resize(n: size_t, value?: T): void;
shrink_to_fit(): void;
clear(): void;
operator[](pos: size_t): T;
at(pos: size_t): T;
front(): T;
back(): T;
data(): T[];
push_back(value: T): void;
pop_back(): void;
emplace_back(...args: any[]): void;
insert(pos: size_t, value: T): void;
insert(pos: size_t, count: size_t, value: T): void;
insert(pos: iterator<T>, first: iterator<T>, last: iterator<T>): iterator<T>;
emplace(pos: iterator<T>, ...args: any[]): iterator<T>;
erase(pos: size_t): void;
erase(first: iterator<T>, last: iterator<T>): iterator<T>;
swap(other: vector<T>): void;
begin(): iterator<T>;
end(): iterator<T>;
rbegin(): reverse_iterator<T>;
rend(): reverse_iterator<T>;
}
class deque<T> {
constructor();
constructor(size: size_t);
constructor(size: size_t, value: T);
constructor(elements: T[]);
constructor(first: iterator<T>, last: iterator<T>);
size(): size_t;
max_size(): size_t;
empty(): boolean;
resize(n: size_t, value?: T): void;
clear(): void;
operator[](pos: size_t): T;
at(pos: size_t): T;
front(): T;
back(): T;
push_front(value: T): void;
push_back(value: T): void;
pop_front(): void;
pop_back(): void;
emplace_front(...args: any[]): void;
emplace_back(...args: any[]): void;
insert(pos: iterator<T>, value: T): iterator<T>;
insert(pos: iterator<T>, count: size_t, value: T): iterator<T>;
insert(pos: iterator<T>, first: iterator<T>, last: iterator<T>): iterator<T>;
emplace(pos: iterator<T>, ...args: any[]): iterator<T>;
erase(pos: iterator<T>): iterator<T>;
erase(first: iterator<T>, last: iterator<T>): iterator<T>;
swap(other: deque<T>): void;
begin(): iterator<T>;
end(): iterator<T>;
rbegin(): reverse_iterator<T>;
rend(): reverse_iterator<T>;
}
class list<T> {
constructor();
constructor(size: size_t);
constructor(size: size_t, value: T);
constructor(elements: T[]);
constructor(first: iterator<T>, last: iterator<T>);
size(): size_t;
max_size(): size_t;
empty(): boolean;
resize(n: size_t, value?: T): void;
clear(): void;
front(): T;
back(): T;
push_front(value: T): void;
push_back(value: T): void;
pop_front(): void;
pop_back(): void;
emplace_front(...args: any[]): void;
emplace_back(...args: any[]): void;
insert(pos: iterator<T>, value: T): iterator<T>;
insert(pos: iterator<T>, count: size_t, value: T): iterator<T>;
insert(pos: iterator<T>, first: iterator<T>, last: iterator<T>): iterator<T>;
emplace(pos: iterator<T>, ...args: any[]): iterator<T>;
erase(pos: iterator<T>): iterator<T>;
erase(first: iterator<T>, last: iterator<T>): iterator<T>;
swap(other: list<T>): void;
merge(other: list<T>): void;
merge(other: list<T>, comp: (a: T, b: T) => boolean): void;
sort(): void;
sort(comp: (a: T, b: T) => boolean): void;
reverse(): void;
unique(): void;
unique(pred: (a: T, b: T) => boolean): void;
splice(pos: iterator<T>, other: list<T>): void;
splice(pos: iterator<T>, other: list<T>, it: iterator<T>): void;
begin(): iterator<T>;
end(): iterator<T>;
rbegin(): reverse_iterator<T>;
rend(): reverse_iterator<T>;
}
// 容器:适配器
class queue<T> {
constructor();
explicit constructor(container: deque<T>);
size(): size_t;
empty(): boolean;
front(): T;
back(): T;
push(value: T): void;
emplace(...args: any[]): void;
pop(): void;
swap(other: queue<T>): void;
}
class stack<T> {
constructor();
explicit constructor(container: deque<T>);
size(): size_t;
empty(): boolean;
top(): T;
push(value: T): void;
emplace(...args: any[]): void;
pop(): void;
swap(other: stack<T>): void;
}
class priority_queue<T> {
constructor();
constructor(comp: (a: T, b: T) => boolean);
constructor(first: iterator<T>, last: iterator<T>);
constructor(first: iterator<T>, last: iterator<T>, comp: (a: T, b: T) => boolean);
size(): size_t;
empty(): boolean;
top(): T;
push(value: T): void;
emplace(...args: any[]): void;
pop(): void;
swap(other: priority_queue<T>): void;
}
// 容器:关联容器
class set<T> {
constructor();
constructor(comp: (a: T, b: T) => boolean);
constructor(first: iterator<T>, last: iterator<T>);
constructor(first: iterator<T>, last: iterator<T>, comp: (a: T, b: T) => boolean);
size(): size_t;
max_size(): size_t;
empty(): boolean;
clear(): void;
insert(value: T): [iterator<T>, boolean];
insert(first: iterator<T>, last: iterator<T>): void;
emplace(...args: any[]): [iterator<T>, boolean];
erase(key: T): size_t;
erase(pos: iterator<T>): iterator<T>;
erase(first: iterator<T>, last: iterator<T>): iterator<T>;
find(key: T): iterator<T>;
count(key: T): size_t;
contains(key: T): boolean;
lower_bound(key: T): iterator<T>;
upper_bound(key: T): iterator<T>;
equal_range(key: T): [iterator<T>, iterator<T>];
swap(other: set<T>): void;
begin(): iterator<T>;
end(): iterator<T>;
rbegin(): reverse_iterator<T>;
rend(): reverse_iterator<T>;
}
class map<K, V> {
constructor();
constructor(comp: (a: K, b: K) => boolean);
constructor(first: iterator<[K, V]>, last: iterator<[K, V]>);
constructor(first: iterator<[K, V]>, last: iterator<[K, V]>, comp: (a: K, b: K) => boolean);
size(): size_t;
max_size(): size_t;
empty(): boolean;
clear(): void;
operator[](key: K): V;
at(key: K): V;
insert(pair: [K, V]): [iterator<[K, V]>, boolean];
insert(first: iterator<[K, V]>, last: iterator<[K, V]>): void;
emplace(key: K, value: V): [iterator<[K, V]>, boolean];
erase(key: K): size_t;
erase(pos: iterator<[K, V]>): iterator<[K, V]>;
erase(first: iterator<[K, V]>, last: iterator<[K, V]>): iterator<[K, V]>;
find(key: K): iterator<[K, V]>;
count(key: K): size_t;
contains(key: K): boolean;
lower_bound(key: K): iterator<[K, V]>;
upper_bound(key: K): iterator<[K, V]>;
equal_range(key: K): [iterator<[K, V]>, iterator<[K, V]>];
swap(other: map<K, V>): void;
begin(): iterator<[K, V]>;
end(): iterator<[K, V]>;
rbegin(): reverse_iterator<[K, V]>;
rend(): reverse_iterator<[K, V]>;
}
class unordered_set<T> {
constructor();
constructor(bucket_count: size_t);
constructor(first: iterator<T>, last: iterator<T>);
constructor(first: iterator<T>, last: iterator<T>, bucket_count: size_t);
size(): size_t;
max_size(): size_t;
empty(): boolean;
clear(): void;
insert(value: T): [iterator<T>, boolean];
insert(first: iterator<T>, last: iterator<T>): void;
emplace(...args: any[]): [iterator<T>, boolean];
erase(key: T): size_t;
erase(pos: iterator<T>): iterator<T>;
erase(first: iterator<T>, last: iterator<T>): iterator<T>;
find(key: T): iterator<T>;
count(key: T): size_t;
contains(key: T): boolean;
bucket_count(): size_t;
max_bucket_count(): size_t;
bucket_size(n: size_t): size_t;
bucket(key: T): size_t;
load_factor(): number;
max_load_factor(): number;
max_load_factor(z: number): void;
rehash(n: size_t): void;
reserve(n: size_t): void;
swap(other: unordered_set<T>): void;
begin(): iterator<T>;
end(): iterator<T>;
begin(n: size_t): iterator<T>;
end(n: size_t): iterator<T>;
}
class unordered_map<K, V> {
constructor();
constructor(bucket_count: size_t);
constructor(first: iterator<[K, V]>, last: iterator<[K, V]>);
constructor(first: iterator<[K, V]>, last: iterator<[K, V]>, bucket_count: size_t);
size(): size_t;
max_size(): size_t;
empty(): boolean;
clear(): void;
operator[](key: K): V;
at(key: K): V;
insert(pair: [K, V]): [iterator<[K, V]>, boolean];
insert(first: iterator<[K, V]>, last: iterator<[K, V]>): void;
emplace(key: K, value: V): [iterator<[K, V]>, boolean];
erase(key: K): size_t;
erase(pos: iterator<[K, V]>): iterator<[K, V]>;
erase(first: iterator<[K, V]>, last: iterator<[K, V]>): iterator<[K, V]>;
find(key: K): iterator<[K, V]>;
count(key: K): size_t;
contains(key: K): boolean;
bucket_count(): size_t;
max_bucket_count(): size_t;
bucket_size(n: size_t): size_t;
bucket(key: K): size_t;
load_factor(): number;
max_load_factor(): number;
max_load_factor(z: number): void;
rehash(n: size_t): void;
reserve(n: size_t): void;
swap(other: unordered_map<K, V>): void;
begin(): iterator<[K, V]>;
end(): iterator<[K, V]>;
begin(n: size_t): iterator<[K, V]>;
end(n: size_t): iterator<[K, V]>;
}
// 智能指针(C++11+)
class unique_ptr<T> {
constructor();
constructor(ptr: T);
constructor(ptr: T, deleter: (p: T) => void);
operator*(): T;
operator->(): T;
get(): T;
release(): T;
reset(ptr?: T): void;
swap(other: unique_ptr<T>): void;
operator bool(): boolean;
}
class shared_ptr<T> {
constructor();
constructor(ptr: T);
constructor(other: shared_ptr<T>);
constructor(other: unique_ptr<T>);
operator*(): T;
operator->(): T;
get(): T;
reset(ptr?: T): void;
swap(other: shared_ptr<T>): void;
operator bool(): boolean;
use_count(): size_t;
unique(): boolean;
}
class weak_ptr<T> {
constructor();
constructor(other: shared_ptr<T>);
constructor(other: weak_ptr<T>);
lock(): shared_ptr<T>;
expired(): boolean;
use_count(): size_t;
reset(): void;
swap(other: weak_ptr<T>): void;
}
function make_unique<T>(...args: any[]): unique_ptr<T>;
function make_shared<T>(...args: any[]): shared_ptr<T>;
// 算法库(扩展版)
namespace algorithm {
// 查找
function find<T>(first: iterator<T>, last: iterator<T>, value: T): iterator<T>;
function find_if<T>(first: iterator<T>, last: iterator<T>, pred: (v: T) => boolean): iterator<T>;
function find_if_not<T>(first: iterator<T>, last: iterator<T>, pred: (v: T) => boolean): iterator<T>;
function find_end<T>(first1: iterator<T>, last1: iterator<T>, first2: iterator<T>, last2: iterator<T>): iterator<T>;
function find_first_of<T>(first1: iterator<T>, last1: iterator<T>, first2: iterator<T>, last2: iterator<T>): iterator<T>;
// 排序
function sort<T>(first: iterator<T>, last: iterator<T>): void;
function sort<T>(first: iterator<T>, last: iterator<T>, comp: (a: T, b: T) => boolean): void;
function stable_sort<T>(first: iterator<T>, last: iterator<T>): void;
function stable_sort<T>(first: iterator<T>, last: iterator<T>, comp: (a: T, b: T) => boolean): void;
function partial_sort<T>(first: iterator<T>, mid: iterator<T>, last: iterator<T>): void;
function partial_sort_copy<T>(first1: iterator<T>, last1: iterator<T>, first2: iterator<T>, last2: iterator<T>): iterator<T>;
// 操作
function copy<T>(first: iterator<T>, last: iterator<T>, result: iterator<T>): iterator<T>;
function copy_if<T>(first: iterator<T>, last: iterator<T>, result: iterator<T>, pred: (v: T) => boolean): iterator<T>;
function move<T>(first: iterator<T>, last: iterator<T>, result: iterator<T>): iterator<T>;
function swap_ranges<T>(first1: iterator<T>, last1: iterator<T>, first2: iterator<T>): iterator<T>;
function fill<T>(first: iterator<T>, last: iterator<T>, value: T): void;
function fill_n<T>(first: iterator<T>, count: size_t, value: T): iterator<T>;
function generate<T>(first: iterator<T>, last: iterator<T>, gen: () => T): void;
function generate_n<T>(first: iterator<T>, count: size_t, gen: () => T): iterator<T>;
// 变换
function transform<T, U>(first: iterator<T>, last: iterator<T>, result: iterator<U>, op: (v: T) => U): iterator<U>;
function transform<T, U, V>(first1: iterator<T>, last1: iterator<T>, first2: iterator<U>, result: iterator<V>, op: (a: T, b: U) => V): iterator<V>;
// 谓词
function all_of<T>(first: iterator<T>, last: iterator<T>, pred: (v: T) => boolean): boolean;
function any_of<T>(first: iterator<T>, last: iterator<T>, pred: (v: T) => boolean): boolean;
function none_of<T>(first: iterator<T>, last: iterator<T>, pred: (v: T) => boolean): boolean;
// 其他
function for_each<T>(first: iterator<T>, last: iterator<T>, func: (v: T) => void): void;
function count<T>(first: iterator<T>, last: iterator<T>, value: T): size_t;
function count_if<T>(first: iterator<T>, last: iterator<T>, pred: (v: T) => boolean): size_t;
function swap<T>(a: T, b: T): void;
function min<T>(a: T, b: T): T;
function max<T>(a: T, b: T): T;
function minmax<T>(a: T, b: T): [T, T];
function clamp<T>(v: T, lo: T, hi: T): T;
}
// 数学库(cmath 扩展版)
namespace math {
// 基本运算
function abs(x: number): number;
function fabs(x: number): number;
function sqrt(x: number): number;
function cbrt(x: number): number;
function hypot(x: number, y: number): number;
function pow(x: number, y: number): number;
function exp(x: number): number;
function exp2(x: number): number;
function log(x: number): number;
function log2(x: number): number;
function log10(x: number): number;
// 三角函数
function sin(x: number): number;
function cos(x: number): number;
function tan(x: number): number;
function asin(x: number): number;
function acos(x: number): number;
function atan(x: number): number;
function atan2(y: number, x: number): number;
// 双曲函数
function sinh(x: number): number;
function cosh(x: number): number;
function tanh(x: number): number;
function asinh(x: number): number;
function acosh(x: number): number;
function atanh(x: number): number;
// 取整函数
function ceil(x: number): number;
function floor(x: number): number;
function round(x: number): number;
function trunc(x: number): number;
function nearbyint(x: number): number;
// 其他
function fmod(x: number, y: number): number;
function remainder(x: number, y: number): number;
function modf(x: number): [number, number];
function ldexp(x: number, exp: number): number;
function frexp(x: number): [number, number];
}
// 线程库(C++11+ 简化版)
namespace thread {
class thread {
constructor(func: (...args: any[]) => void, ...args: any[]);
join(): void;
detach(): void;
joinable(): boolean;
get_id(): number;
swap(other: thread): void;
static hardware_concurrency(): size_t;
}
class mutex {
lock(): void;
unlock(): void;
try_lock(): boolean;
}
class recursive_mutex {
lock(): void;
unlock(): void;
try_lock(): boolean;
}
class lock_guard<T> {
constructor(mutex: T);
}
class unique_lock<T> {
constructor(mutex: T);
constructor(mutex: T, defer_lock_t: any);
constructor(mutex: T, try_to_lock_t: any);
constructor(mutex: T, adopt_lock_t: any);
lock(): void;
try_lock(): boolean;
unlock(): void;
release(): T;
owns_lock(): boolean;
operator bool(): boolean;
swap(other: unique_lock<T>): void;
}
function lock<T>(...mutexes: T[]): void;
function try_lock<T>(...mutexes: T[]): number;
}
// 时间库(C++11+ 简化版)
namespace chrono {
type nanoseconds = number;
type microseconds = number;
type milliseconds = number;
type seconds = number;
type minutes = number;
type hours = number;
class system_clock {
static now(): number;
static to_time_t(time: number): number;
static from_time_t(time: number): number;
}
class steady_clock {
static now(): number;
}
function duration_cast<T>(d: number): T;
}
}
// C 标准库函数
declare function printf(format: string, ...args: any[]): number;
declare function fprintf(stream: any, format: string, ...args: any[]): number;
declare function sprintf(buffer: string, format: string, ...args: any[]): number;
declare function scanf(format: string, ...args: any[]): number;
declare function fscanf(stream: any, format: string, ...args: any[]): number;
declare function sscanf(buffer: string, format: string, ...args: any[]): number;
declare function malloc(size: std.size_t): any;
declare function calloc(nmemb: std.size_t, size: std.size_t): any;
declare function realloc(ptr: any, size: std.size_t): any;
declare function free(ptr: any): void;
declare function memcpy(dest: any, src: any, n: std.size_t): any;
declare function memmove(dest: any, src: any, n: std.size_t): any;
declare function memset(ptr: any, value: number, num: std.size_t): any;
declare function memcmp(ptr1: any, ptr2: any, num: std.size_t): number;
declare function strcpy(dest: string, src: string): string;
declare function strncpy(dest: string, src: string, n: std.size_t): string;
declare function strcat(dest: string, src: string): string;
declare function strncat(dest: string, src: string, n: std.size_t): string;
declare function strcmp(str1: string, str2: string): number;
declare function strncmp(str1: string, str2: string, n: std.size_t): number;
declare function strlen(str: string): std.size_t;
declare function strchr(str: string, c: string): string;
declare function strrchr(str: string, c: string): string;
declare function strstr(str1: string, str2: string): string;
// 宏定义
declare const NULL: null;
declare const EOF: number;
declare const EXIT_SUCCESS: number;
declare const EXIT_FAILURE: number;
// C++ 关键字(作为类型提示)
declare type inline = any;
declare type virtual = any;
declare type explicit = any;
declare type mutable = any;
declare type constexpr = any;
declare type noexcept = any;
declare type override = any;
declare type final = any;
declare type thread_local = any;
/*!
* testlib.h 的完整 TypeScript 声明
* https://github.com/MikeMirzayanov/testlib
*
* 用法示例(Monaco):
* import * as testlib from './testlib';
* testlib.registerValidation();
* const n = testlib.inf.readInt();
*/
// ------------------------------------------------------------------
// 枚举 & 基础类型
// ------------------------------------------------------------------
export type TResult =
| '_ok'
| '_wa'
| '_pe'
| '_fail'
| '_dirt'
| '_points'
| '_unexpected_eof'
| '_partially';
export type TMode = '_input' | '_output' | '_answer';
export type TTestlibMode =
| '_unknown'
| '_checker'
| '_validator'
| '_generator'
| '_interactor'
| '_scorer';
export interface TestResult {
testIndex: number;
testset: string;
group: string;
verdict:
| 'SKIPPED'
| 'OK'
| 'WRONG_ANSWER'
| 'RUNTIME_ERROR'
| 'TIME_LIMIT_EXCEEDED'
| 'IDLENESS_LIMIT_EXCEEDED'
| 'MEMORY_LIMIT_EXCEEDED'
| 'COMPILATION_ERROR'
| 'CRASHED'
| 'FAILED';
points: number;
timeConsumed: bigint;
memoryConsumed: bigint;
input: string;
output: string;
answer: string;
exitCode: number;
checkerComment: string;
}
// ------------------------------------------------------------------
// pattern
// ------------------------------------------------------------------
export declare class Pattern {
constructor(src: string);
next(r: Random): string;
matches(s: string): boolean;
src(): string;
}
// ------------------------------------------------------------------
// Random
// ------------------------------------------------------------------
export declare class Random {
/** [0, n) */
next(n: number): number;
/** [from, to] */
next(from: number, to: number): number;
/** [0, n) */
next(n: bigint): bigint;
/** [from, to] */
next(from: bigint, to: bigint): bigint;
/** 0-1 double */
next(): number;
/** 正则/模式字符串 */
next(pattern: string): string;
/** 带权随机 */
wnext(n: number, type: number): number;
wnext(from: number, to: number, type: number): number;
/** 随机排列 */
perm<T = number>(size: T, first?: T): T[];
/** 不重复随机数 */
distinct(size: number, upper: number): number[];
distinct(size: number, from: number, to: number): number[];
/** 随机划分 */
partition(size: number, sum: number, minPart?: number): number[];
/** 从容器随机取一个元素 */
any<T>(container: readonly T[]): T;
}
// ------------------------------------------------------------------
// InStream
// ------------------------------------------------------------------
export interface InStream {
/** 初始化文件流 */
init(fileName: string, mode: TMode): void;
init(file: File, mode: TMode): void;
reset(file?: File): void;
// ---------- 基础读取 ----------
readChar(): string;
readChar(expected: string): string;
readSpace(): string;
skipBlanks(): void;
eof(): boolean;
seekEof(): boolean;
readEof(): void;
readEoln(): void;
// ---------- 字符串 / 行 ----------
readWord(): string;
readWord(pattern: string | Pattern, variableName?: string): string;
readWords(
size: number,
pattern?: string | Pattern,
variablesName?: string,
indexBase?: number,
): string[];
readLine(): string;
readLines(size: number, indexBase?: number): string[];
// ---------- 整数 ----------
readInt(): number;
readInt(minv: number, maxv: number, variableName?: string): number;
readInts(
size: number,
minv?: number,
maxv?: number,
variablesName?: string,
indexBase?: number,
): number[];
readLong(): bigint;
readLong(minv: bigint, maxv: bigint, variableName?: string): bigint;
readLongs(
size: number,
minv?: bigint,
maxv?: bigint,
variablesName?: string,
indexBase?: number,
): bigint[];
readUnsignedLong(): bigint;
readUnsignedLong(
minv: bigint,
maxv: bigint,
variableName?: string,
): bigint;
readUnsignedLongs(
size: number,
minv?: bigint,
maxv?: bigint,
variablesName?: string,
indexBase?: number,
): bigint[];
// ---------- 浮点 ----------
readReal(): number;
readReal(minv: number, maxv: number, variableName?: string): number;
readReals(
size: number,
minv?: number,
maxv?: number,
variablesName?: string,
indexBase?: number,
): number[];
readDouble(): number;
readDouble(minv: number, maxv: number, variableName?: string): number;
readDoubles(
size: number,
minv?: number,
maxv?: number,
variablesName?: string,
indexBase?: number,
): number[];
// ---------- 严格格式 ----------
readStrictReal(
minv: number,
maxv: number,
minAfterPointDigitCount: number,
maxAfterPointDigitCount: number,
variableName?: string,
): number;
readStrictReals(
size: number,
minv: number,
maxv: number,
minAfterPointDigitCount: number,
maxAfterPointDigitCount: number,
variablesName?: string,
indexBase?: number,
): number[];
readStrictDouble(
minv: number,
maxv: number,
minAfterPointDigitCount: number,
maxAfterPointDigitCount: number,
variableName?: string,
): number;
readStrictDoubles(
size: number,
minv: number,
maxv: number,
minAfterPointDigitCount: number,
maxAfterPointDigitCount: number,
variablesName?: string,
indexBase?: number,
): number[];
}
// ------------------------------------------------------------------
// 全局流
// ------------------------------------------------------------------
export declare const inf: InStream;
export declare const ouf: InStream;
export declare const ans: InStream;
export declare const rnd: Random;
// ------------------------------------------------------------------
// 注册函数
// ------------------------------------------------------------------
/**
* 注册为 checker
* 命令行顺序: [--testset tests] [--group A] <input> <output> <answer> [report] [-appes]
*/
export declare function registerTestlibCmd(
argc: number,
argv: string[],
): void;
/**
* 注册为 validator
*/
export declare function registerValidation(
argc?: number,
argv?: string[],
): void;
/**
* 注册为 generator
* 版本 1 为最新随机算法,0 为兼容旧版本
*/
export declare function registerGen(
argc: number,
argv: string[],
version?: 0 | 1,
): void;
/**
* 注册为 interactor
*/
export declare function registerInteraction(
argc: number,
argv: string[],
): void;
/**
* 注册为 scorer
*/
export declare function registerScorer(
argc: number,
argv: string[],
scorer: (results: TestResult[]) => number,
): void;
// ------------------------------------------------------------------
// 退出 / 报错
// ------------------------------------------------------------------
/**
* 直接退出
*/
export declare function quit(result: TResult, message: string): never;
/**
* 格式化退出
*/
export declare function quitf(
result: TResult,
format: string,
...args: any[]
): never;
/**
* 按分数退出
*/
export declare function quitp(points: number, message?: string): never;
// ------------------------------------------------------------------
// 工具
// ------------------------------------------------------------------
/**
* 设置 checker 名称
*/
export declare function setName(format: string, ...args: any[]): void;
/**
* 添加 validator feature
*/
export declare function addFeature(feature: string): void;
/**
* 标记已使用的 feature
*/
export declare function feature(feature: string): void;
/**
* 随机打乱
*/
export declare function shuffle<T>(begin: T[], end: T[]): void;
/**
* 连接
*/
export declare function join<T>(
collection: readonly T[],
separator?: string,
): string;
/**
* 分割
*/
export declare function split(
s: string,
separator: string | readonly string[],
): string[];
export declare function tokenize(
s: string,
separator: string | readonly string[],
): string[];
// ------------------------------------------------------------------
// 命令行参数解析
// ------------------------------------------------------------------
export declare function opt<T = string>(key: string): T;
export declare function opt<T = string>(
key: string,
defaultValue: T,
): T;
export declare function opt<T = string>(index: number): T;
export declare function opt<T = string>(
index: number,
defaultValue: T,
): T;
export declare function has_opt(key: string): boolean;
// ------------------------------------------------------------------
// UMD 全局声明
// ------------------------------------------------------------------
export as namespace testlib;
`