@routilet/c-exam-kit 0.0.0-stage → 0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2644 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "version": "0.6.10",
4
+ "notes": "## 开始使用\n保留题目 `main.c` 中自动生成的脚手架头文件引用,不要手动添加或修改路径。函数可以直接调用;本地测试和提交时,Companion 会自动装配所需代码。\n手册示例分为调用片段和包含 `main` 的程序框架。复制后按题意调整;程序框架应放在原有头文件引用下方,不要重复定义 `main`。\n\n## 输入与输出\n库内输入函数统一使用,不与 `scanf`、`getchar`、`fgets` 等标准输入函数混用。输出可以正常使用 `printf`。\n`read_*` 遇到提前 EOF 或无效输入时结束程序;`try_read_*` 仅在正常 EOF 时返回 false。注意区分读单词、读整行和读本行剩余内容。\n\n## 类型、下标与区间\n`_ints`、`_lls`、`_doubles` 分别表示 int、long long、double 数组。下标从 0 开始,`n` 表示参与操作的元素数量;区间 `[l, r)` 包含 l,不包含 r。具体返回值和失败标记以条目说明为准。\n\n## 数组与字符串容量\n自动容量接口必须传入当前作用域的实际数组。指针、动态分配缓冲区或函数的数组形参使用 `*_into`,显式传入容量。字符数组容量包含结尾的 `\\0`;字符串操作按字节处理,不是 Unicode 字符级操作。\n\n## 错误与使用条件\n非法参数、容量不足或溢出通常会输出错误信息并终止程序。按条目要求初始化变量、分配足够容量并满足排序等前置条件。浮点数组的相等查找通常采用精确比较;近似比较请使用相应接口。",
5
+ "categories": [
6
+ {
7
+ "title": "输入与输出",
8
+ "entries": [
9
+ {
10
+ "id": "read_number",
11
+ "title": "读一个数",
12
+ "description": "从标准输入读取指定类型的一个数。正常读取之外,提前遇到 EOF、格式无效和数值超出范围分别报错。格式或范围错误会显示一段输入。",
13
+ "keywords": [
14
+ "数字",
15
+ "整数",
16
+ "浮点",
17
+ "scanf"
18
+ ],
19
+ "related": [],
20
+ "advancedSignatures": [],
21
+ "signatures": [
22
+ "int read_int(void);",
23
+ "long long read_ll(void);",
24
+ "double read_double(void);"
25
+ ],
26
+ "example": "int x = read_int();",
27
+ "variants": [
28
+ {
29
+ "key": "int",
30
+ "label": "int",
31
+ "symbols": [
32
+ "read_int"
33
+ ],
34
+ "signatures": [
35
+ "int read_int(void);"
36
+ ],
37
+ "advancedSignatures": [],
38
+ "note": "",
39
+ "example": "int x = read_int();"
40
+ },
41
+ {
42
+ "key": "ll",
43
+ "label": "long long",
44
+ "symbols": [
45
+ "read_ll"
46
+ ],
47
+ "signatures": [
48
+ "long long read_ll(void);"
49
+ ],
50
+ "advancedSignatures": [],
51
+ "note": "",
52
+ "example": "long long x = read_ll();"
53
+ },
54
+ {
55
+ "key": "double",
56
+ "label": "double",
57
+ "symbols": [
58
+ "read_double"
59
+ ],
60
+ "signatures": [
61
+ "double read_double(void);"
62
+ ],
63
+ "advancedSignatures": [],
64
+ "note": "",
65
+ "example": "double x = read_double();"
66
+ }
67
+ ],
68
+ "commonSignatures": []
69
+ },
70
+ {
71
+ "id": "try_read_number",
72
+ "title": "尝试读取一个数",
73
+ "description": "读到数时返回 `true`,正常 EOF 返回 `false`。传入存放结果的变量地址。格式无效或数值越界时结束程序,诊断会显示相应原因和一段输入。",
74
+ "keywords": [
75
+ "EOF",
76
+ "循环",
77
+ "输入"
78
+ ],
79
+ "related": [],
80
+ "advancedSignatures": [],
81
+ "signatures": [
82
+ "bool try_read_int(int *value);",
83
+ "bool try_read_ll(long long *value);",
84
+ "bool try_read_double(double *value);"
85
+ ],
86
+ "example": "int x;\nwhile (try_read_int(&x)) {\n // 使用 x\n}",
87
+ "variants": [
88
+ {
89
+ "key": "int",
90
+ "label": "int",
91
+ "symbols": [
92
+ "try_read_int"
93
+ ],
94
+ "signatures": [
95
+ "bool try_read_int(int *value);"
96
+ ],
97
+ "advancedSignatures": [],
98
+ "note": "",
99
+ "example": "int x;\nwhile (try_read_int(&x)) {\n // 使用 x\n}"
100
+ },
101
+ {
102
+ "key": "ll",
103
+ "label": "long long",
104
+ "symbols": [
105
+ "try_read_ll"
106
+ ],
107
+ "signatures": [
108
+ "bool try_read_ll(long long *value);"
109
+ ],
110
+ "advancedSignatures": [],
111
+ "note": "",
112
+ "example": "long long x;\nwhile (try_read_ll(&x)) {\n // 使用 x\n}"
113
+ },
114
+ {
115
+ "key": "double",
116
+ "label": "double",
117
+ "symbols": [
118
+ "try_read_double"
119
+ ],
120
+ "signatures": [
121
+ "bool try_read_double(double *value);"
122
+ ],
123
+ "advancedSignatures": [],
124
+ "note": "",
125
+ "example": "double x;\nwhile (try_read_double(&x)) {\n // 使用 x\n}"
126
+ }
127
+ ],
128
+ "commonSignatures": []
129
+ },
130
+ {
131
+ "id": "print_number",
132
+ "title": "输出一个数",
133
+ "description": "输出数值后追加 end 字符串(例如换行或空格)。double 版本额外指定小数位数。",
134
+ "keywords": [
135
+ "输出",
136
+ "printf",
137
+ "精度"
138
+ ],
139
+ "related": [],
140
+ "advancedSignatures": [],
141
+ "signatures": [
142
+ "void print_int(int value, const char *end);",
143
+ "void print_ll(long long value, const char *end);",
144
+ "void print_double(double value, int digits, const char *end);"
145
+ ],
146
+ "example": "print_int(42, \"\\n\");",
147
+ "variants": [
148
+ {
149
+ "key": "int",
150
+ "label": "int",
151
+ "symbols": [
152
+ "print_int"
153
+ ],
154
+ "signatures": [
155
+ "void print_int(int value, const char *end);"
156
+ ],
157
+ "advancedSignatures": [],
158
+ "note": "",
159
+ "example": "print_int(42, \"\\n\");"
160
+ },
161
+ {
162
+ "key": "ll",
163
+ "label": "long long",
164
+ "symbols": [
165
+ "print_ll"
166
+ ],
167
+ "signatures": [
168
+ "void print_ll(long long value, const char *end);"
169
+ ],
170
+ "advancedSignatures": [],
171
+ "note": "",
172
+ "example": "print_ll(42, \"\\n\");"
173
+ },
174
+ {
175
+ "key": "double",
176
+ "label": "double",
177
+ "symbols": [
178
+ "print_double"
179
+ ],
180
+ "signatures": [
181
+ "void print_double(double value, int digits, const char *end);"
182
+ ],
183
+ "advancedSignatures": [],
184
+ "note": "",
185
+ "example": "print_double(3.14159, 2, \"\\n\");"
186
+ }
187
+ ],
188
+ "commonSignatures": []
189
+ },
190
+ {
191
+ "id": "read_char",
192
+ "title": "读一个字符",
193
+ "description": "`read_char()` 跳过空白;`read_char_raw()` 保留空格和换行。提前遇到 EOF 时结束程序。",
194
+ "keywords": [
195
+ "字符",
196
+ "空格",
197
+ "换行",
198
+ "getchar"
199
+ ],
200
+ "related": [],
201
+ "advancedSignatures": [],
202
+ "signatures": [
203
+ "char read_char(void);",
204
+ "char read_char_raw(void);"
205
+ ],
206
+ "example": "char ch = read_char();"
207
+ },
208
+ {
209
+ "id": "try_read_char",
210
+ "title": "尝试读取字符",
211
+ "description": "正常 EOF 返回 false;`try_read_char` 跳过空白,`try_read_char_raw` 保留空白。",
212
+ "keywords": [
213
+ "EOF",
214
+ "字符",
215
+ "getchar"
216
+ ],
217
+ "related": [],
218
+ "advancedSignatures": [],
219
+ "signatures": [
220
+ "bool try_read_char(char *value);",
221
+ "bool try_read_char_raw(char *value);"
222
+ ],
223
+ "example": "char ch;\nwhile (try_read_char_raw(&ch)) {\n print_char(ch, \"\");\n}"
224
+ },
225
+ {
226
+ "id": "print_char",
227
+ "title": "输出字符",
228
+ "description": "输出一个字符,再追加 end 字符串。",
229
+ "keywords": [
230
+ "输出",
231
+ "字符"
232
+ ],
233
+ "related": [],
234
+ "advancedSignatures": [],
235
+ "signatures": [
236
+ "void print_char(char value, const char *end);"
237
+ ],
238
+ "example": "print_char('A', \"\\n\");"
239
+ },
240
+ {
241
+ "id": "read_word",
242
+ "title": "读一个单词",
243
+ "description": "跳过前导空白,读取一个不含空白的单词。try 版本在正常 EOF 返回 false。普通宏要求实际字符数组;指针使用 *_into,容量包含结束符。单词过长时,诊断会显示缓冲区容量和可容纳的内容字节数。",
244
+ "keywords": [
245
+ "字符串",
246
+ "单词",
247
+ "scanf",
248
+ "EOF"
249
+ ],
250
+ "related": [],
251
+ "advancedSignatures": [
252
+ "void read_word_into(char *out, size_t capacity);",
253
+ "bool try_read_word_into(char *out, size_t capacity);"
254
+ ],
255
+ "signatures": [
256
+ "read_word(array)",
257
+ "try_read_word(array)",
258
+ "void read_word_into(char *out, size_t capacity);",
259
+ "bool try_read_word_into(char *out, size_t capacity);"
260
+ ],
261
+ "example": "char word[100];\nread_word(word);"
262
+ },
263
+ {
264
+ "id": "read_line",
265
+ "title": "读一整行",
266
+ "description": "读取下一整行,不保留行结束符。若前面已经读取本行的一部分 token,先丢弃本行剩余内容。保留真正的空行。try 版本正常 EOF 返回 false;指针使用 *_into。整行太长时,诊断会显示缓冲区容量和可容纳的内容字节数。",
267
+ "keywords": [
268
+ "字符串",
269
+ "整行",
270
+ "fgets",
271
+ "EOF"
272
+ ],
273
+ "related": [],
274
+ "advancedSignatures": [
275
+ "void read_line_into(char *out, size_t capacity);",
276
+ "bool try_read_line_into(char *out, size_t capacity);"
277
+ ],
278
+ "signatures": [
279
+ "read_line(array)",
280
+ "try_read_line(array)",
281
+ "void read_line_into(char *out, size_t capacity);",
282
+ "bool try_read_line_into(char *out, size_t capacity);"
283
+ ],
284
+ "example": "char line[100];\nread_line(line);"
285
+ },
286
+ {
287
+ "id": "read_rest",
288
+ "title": "读本行剩余内容",
289
+ "description": "读取当前行剩余内容,保留前导空白,不保留行结束符。try 版本正常 EOF 返回 false;指针使用 *_into。剩余内容太长时,诊断会显示缓冲区容量和可容纳的内容字节数。",
290
+ "keywords": [
291
+ "字符串",
292
+ "换行",
293
+ "空格",
294
+ "EOF"
295
+ ],
296
+ "related": [],
297
+ "advancedSignatures": [
298
+ "void read_rest_into(char *out, size_t capacity);",
299
+ "bool try_read_rest_into(char *out, size_t capacity);"
300
+ ],
301
+ "signatures": [
302
+ "read_rest(array)",
303
+ "try_read_rest(array)",
304
+ "void read_rest_into(char *out, size_t capacity);",
305
+ "bool try_read_rest_into(char *out, size_t capacity);"
306
+ ],
307
+ "example": "int n = read_int();\nchar rest[100];\nread_rest(rest);"
308
+ },
309
+ {
310
+ "id": "skip_line",
311
+ "title": "跳过本行",
312
+ "description": "丢弃当前行剩余输入,直到行结束或 EOF。",
313
+ "keywords": [
314
+ "忽略",
315
+ "换行"
316
+ ],
317
+ "related": [],
318
+ "advancedSignatures": [],
319
+ "signatures": [
320
+ "void skip_line(void);"
321
+ ],
322
+ "example": "skip_line();"
323
+ },
324
+ {
325
+ "id": "print_text",
326
+ "title": "输出字符串",
327
+ "description": "输出以零结尾的字符串,再追加 end 字符串。",
328
+ "keywords": [
329
+ "输出",
330
+ "文本"
331
+ ],
332
+ "related": [],
333
+ "advancedSignatures": [],
334
+ "signatures": [
335
+ "void print_text(const char *value, const char *end);"
336
+ ],
337
+ "example": "print_text(\"hello\", \"\\n\");"
338
+ },
339
+ {
340
+ "id": "read_arrays",
341
+ "title": "读数组",
342
+ "description": "连续读取 n 个元素,写入已有数组。n 是读取数量,不是容量。普通接口要求实际数组;指针用显式容量的第二个接口,容量单位为元素。",
343
+ "keywords": [
344
+ "数组",
345
+ "输入",
346
+ "容量"
347
+ ],
348
+ "related": [],
349
+ "advancedSignatures": [],
350
+ "signatures": [
351
+ "read_ints(array, count)",
352
+ "void read_ints_into(int *array, int count, size_t capacity);",
353
+ "read_lls(array, count)",
354
+ "void read_lls_into(long long *array, int count, size_t capacity);",
355
+ "read_doubles(array, count)",
356
+ "void read_doubles_into(double *array, int count, size_t capacity);"
357
+ ],
358
+ "example": "int a[100];\nint n = read_int();\nread_ints(a, n);",
359
+ "variants": [
360
+ {
361
+ "key": "int",
362
+ "label": "int",
363
+ "symbols": [
364
+ "read_ints",
365
+ "read_ints_into"
366
+ ],
367
+ "signatures": [
368
+ "read_ints(array, count)",
369
+ "void read_ints_into(int *array, int count, size_t capacity);"
370
+ ],
371
+ "advancedSignatures": [
372
+ "void read_ints_into(int *array, int count, size_t capacity);"
373
+ ],
374
+ "note": "",
375
+ "example": "int a[100];\nint n = read_int();\nread_ints(a, n);"
376
+ },
377
+ {
378
+ "key": "ll",
379
+ "label": "long long",
380
+ "symbols": [
381
+ "read_lls",
382
+ "read_lls_into"
383
+ ],
384
+ "signatures": [
385
+ "read_lls(array, count)",
386
+ "void read_lls_into(long long *array, int count, size_t capacity);"
387
+ ],
388
+ "advancedSignatures": [
389
+ "void read_lls_into(long long *array, int count, size_t capacity);"
390
+ ],
391
+ "note": "",
392
+ "example": "long long a[100];\nint n = read_int();\nread_lls(a, n);"
393
+ },
394
+ {
395
+ "key": "double",
396
+ "label": "double",
397
+ "symbols": [
398
+ "read_doubles",
399
+ "read_doubles_into"
400
+ ],
401
+ "signatures": [
402
+ "read_doubles(array, count)",
403
+ "void read_doubles_into(double *array, int count, size_t capacity);"
404
+ ],
405
+ "advancedSignatures": [
406
+ "void read_doubles_into(double *array, int count, size_t capacity);"
407
+ ],
408
+ "note": "",
409
+ "example": "double a[100];\nint n = read_int();\nread_doubles(a, n);"
410
+ }
411
+ ],
412
+ "commonSignatures": []
413
+ },
414
+ {
415
+ "id": "print_arrays",
416
+ "title": "输出数组",
417
+ "description": "输出前 n 个元素,sep 只放在元素之间,end 在最后输出。double 版本额外指定小数位数。",
418
+ "keywords": [
419
+ "数组",
420
+ "输出",
421
+ "分隔符",
422
+ "精度"
423
+ ],
424
+ "related": [],
425
+ "advancedSignatures": [],
426
+ "signatures": [
427
+ "void print_ints(const int *array, int count,\n const char *separator, const char *end);",
428
+ "void print_lls(const long long *array, int count,\n const char *separator, const char *end);",
429
+ "void print_doubles(const double *array, int count, int digits,\n const char *separator, const char *end);"
430
+ ],
431
+ "example": "int a[] = {1, 2, 3};\nprint_ints(a, 3, \" \", \"\\n\");",
432
+ "variants": [
433
+ {
434
+ "key": "int",
435
+ "label": "int",
436
+ "symbols": [
437
+ "print_ints"
438
+ ],
439
+ "signatures": [
440
+ "void print_ints(const int *array, int count,\n const char *separator, const char *end);"
441
+ ],
442
+ "advancedSignatures": [],
443
+ "note": "",
444
+ "example": "int a[] = {1, 2, 3};\nprint_ints(a, 3, \" \", \"\\n\");"
445
+ },
446
+ {
447
+ "key": "ll",
448
+ "label": "long long",
449
+ "symbols": [
450
+ "print_lls"
451
+ ],
452
+ "signatures": [
453
+ "void print_lls(const long long *array, int count,\n const char *separator, const char *end);"
454
+ ],
455
+ "advancedSignatures": [],
456
+ "note": "",
457
+ "example": "long long a[] = {1, 2, 3};\nprint_lls(a, 3, \" \", \"\\n\");"
458
+ },
459
+ {
460
+ "key": "double",
461
+ "label": "double",
462
+ "symbols": [
463
+ "print_doubles"
464
+ ],
465
+ "signatures": [
466
+ "void print_doubles(const double *array, int count, int digits,\n const char *separator, const char *end);"
467
+ ],
468
+ "advancedSignatures": [],
469
+ "note": "",
470
+ "example": "double a[] = {1.5, 2.5};\nprint_doubles(a, 2, 2, \" \", \"\\n\");"
471
+ }
472
+ ],
473
+ "commonSignatures": []
474
+ }
475
+ ]
476
+ },
477
+ {
478
+ "title": "数组与结构体",
479
+ "entries": [
480
+ {
481
+ "id": "fill_arrays",
482
+ "title": "填充数组",
483
+ "description": "将前 n 项设为 value;不会改变数组容量。普通接口要求实际数组,指针用显式容量接口。",
484
+ "keywords": [],
485
+ "related": [],
486
+ "advancedSignatures": [],
487
+ "signatures": [
488
+ "fill_ints(array, n, value)",
489
+ "void fill_ints_into(int *array, int n, int value, size_t capacity);",
490
+ "fill_lls(a,n,value)",
491
+ "void fill_lls_into(long long *a, int n, long long value,\n size_t capacity);",
492
+ "fill_doubles(a,n,value)",
493
+ "void fill_doubles_into(double *a,int n,double value,\n size_t capacity);"
494
+ ],
495
+ "example": "int a[10];\nfill_ints(a, 10, 5);",
496
+ "variants": [
497
+ {
498
+ "key": "int",
499
+ "label": "int",
500
+ "symbols": [
501
+ "fill_ints",
502
+ "fill_ints_into"
503
+ ],
504
+ "signatures": [
505
+ "fill_ints(array, n, value)",
506
+ "void fill_ints_into(int *array, int n, int value, size_t capacity);"
507
+ ],
508
+ "advancedSignatures": [
509
+ "void fill_ints_into(int *array, int n, int value, size_t capacity);"
510
+ ],
511
+ "note": "",
512
+ "example": "int a[10];\nfill_ints(a, 10, 5);"
513
+ },
514
+ {
515
+ "key": "ll",
516
+ "label": "long long",
517
+ "symbols": [
518
+ "fill_lls",
519
+ "fill_lls_into"
520
+ ],
521
+ "signatures": [
522
+ "fill_lls(a,n,value)",
523
+ "void fill_lls_into(long long *a, int n, long long value,\n size_t capacity);"
524
+ ],
525
+ "advancedSignatures": [
526
+ "void fill_lls_into(long long *a, int n, long long value,\n size_t capacity);"
527
+ ],
528
+ "note": "",
529
+ "example": "long long a[10];\nfill_lls(a, 10, 5);"
530
+ },
531
+ {
532
+ "key": "double",
533
+ "label": "double",
534
+ "symbols": [
535
+ "fill_doubles",
536
+ "fill_doubles_into"
537
+ ],
538
+ "signatures": [
539
+ "fill_doubles(a,n,value)",
540
+ "void fill_doubles_into(double *a,int n,double value,\n size_t capacity);"
541
+ ],
542
+ "advancedSignatures": [
543
+ "void fill_doubles_into(double *a,int n,double value,\n size_t capacity);"
544
+ ],
545
+ "note": "",
546
+ "example": "double a[10];\nfill_doubles(a, 10, 5);"
547
+ }
548
+ ],
549
+ "commonSignatures": []
550
+ },
551
+ {
552
+ "id": "copy_arrays",
553
+ "title": "复制数组",
554
+ "description": "从 src 复制 n 项到 dst,目标容量至少 n。两个数组不应重叠;指针目标用显式容量接口。",
555
+ "keywords": [],
556
+ "related": [],
557
+ "advancedSignatures": [],
558
+ "signatures": [
559
+ "copy_ints(array, source, n)",
560
+ "void copy_ints_into(int *destination, const int *source,\n int n, size_t capacity);",
561
+ "copy_lls(a,src,n)",
562
+ "void copy_lls_into(long long *dest,const long long *src,int n,\n size_t capacity);",
563
+ "copy_doubles(a,src,n)",
564
+ "void copy_doubles_into(double *dst,const double *src,int n,\n size_t capacity);"
565
+ ],
566
+ "example": "int src[] = {1, 2, 3}, dst[3];\ncopy_ints(dst, src, 3);",
567
+ "variants": [
568
+ {
569
+ "key": "int",
570
+ "label": "int",
571
+ "symbols": [
572
+ "copy_ints",
573
+ "copy_ints_into"
574
+ ],
575
+ "signatures": [
576
+ "copy_ints(array, source, n)",
577
+ "void copy_ints_into(int *destination, const int *source,\n int n, size_t capacity);"
578
+ ],
579
+ "advancedSignatures": [
580
+ "void copy_ints_into(int *destination, const int *source,\n int n, size_t capacity);"
581
+ ],
582
+ "note": "",
583
+ "example": "int src[] = {1, 2, 3}, dst[3];\ncopy_ints(dst, src, 3);"
584
+ },
585
+ {
586
+ "key": "ll",
587
+ "label": "long long",
588
+ "symbols": [
589
+ "copy_lls",
590
+ "copy_lls_into"
591
+ ],
592
+ "signatures": [
593
+ "copy_lls(a,src,n)",
594
+ "void copy_lls_into(long long *dest,const long long *src,int n,\n size_t capacity);"
595
+ ],
596
+ "advancedSignatures": [
597
+ "void copy_lls_into(long long *dest,const long long *src,int n,\n size_t capacity);"
598
+ ],
599
+ "note": "",
600
+ "example": "long long src[] = {1, 2, 3}, dst[3];\ncopy_lls(dst, src, 3);"
601
+ },
602
+ {
603
+ "key": "double",
604
+ "label": "double",
605
+ "symbols": [
606
+ "copy_doubles",
607
+ "copy_doubles_into"
608
+ ],
609
+ "signatures": [
610
+ "copy_doubles(a,src,n)",
611
+ "void copy_doubles_into(double *dst,const double *src,int n,\n size_t capacity);"
612
+ ],
613
+ "advancedSignatures": [
614
+ "void copy_doubles_into(double *dst,const double *src,int n,\n size_t capacity);"
615
+ ],
616
+ "note": "",
617
+ "example": "double src[] = {1, 2, 3}, dst[3];\ncopy_doubles(dst, src, 3);"
618
+ }
619
+ ],
620
+ "commonSignatures": []
621
+ },
622
+ {
623
+ "id": "values_arrays",
624
+ "title": "从给定数据构造数组",
625
+ "description": "将参数列表写入数组,返回写入元素数。普通接口要求实际数组;显式容量接口接收源数组、元素数、目标容量。",
626
+ "keywords": [],
627
+ "related": [],
628
+ "advancedSignatures": [],
629
+ "signatures": [
630
+ "values_ints(array, ...)",
631
+ "int values_ints_into(int *destination, const int *values,\n size_t count, size_t capacity);",
632
+ "values_lls(array, ...)",
633
+ "int values_lls_into(long long *destination,\n const long long *items, size_t count,\n size_t capacity);",
634
+ "values_doubles(array, ...)",
635
+ "int values_doubles_into(double *destination,\n const double *items, size_t count,\n size_t capacity);"
636
+ ],
637
+ "example": "int a[10];\nint n = values_ints(a, 4, 1, 3);",
638
+ "variants": [
639
+ {
640
+ "key": "int",
641
+ "label": "int",
642
+ "symbols": [
643
+ "values_ints",
644
+ "values_ints_into"
645
+ ],
646
+ "signatures": [
647
+ "values_ints(array, ...)",
648
+ "int values_ints_into(int *destination, const int *values,\n size_t count, size_t capacity);"
649
+ ],
650
+ "advancedSignatures": [
651
+ "int values_ints_into(int *destination, const int *values,\n size_t count, size_t capacity);"
652
+ ],
653
+ "note": "",
654
+ "example": "int a[10];\nint n = values_ints(a, 4, 1, 3);"
655
+ },
656
+ {
657
+ "key": "ll",
658
+ "label": "long long",
659
+ "symbols": [
660
+ "values_lls",
661
+ "values_lls_into"
662
+ ],
663
+ "signatures": [
664
+ "values_lls(array, ...)",
665
+ "int values_lls_into(long long *destination,\n const long long *items, size_t count,\n size_t capacity);"
666
+ ],
667
+ "advancedSignatures": [
668
+ "int values_lls_into(long long *destination,\n const long long *items, size_t count,\n size_t capacity);"
669
+ ],
670
+ "note": "",
671
+ "example": "long long a[10];\nint n = values_lls(a, 4, 1, 3);"
672
+ },
673
+ {
674
+ "key": "double",
675
+ "label": "double",
676
+ "symbols": [
677
+ "values_doubles",
678
+ "values_doubles_into"
679
+ ],
680
+ "signatures": [
681
+ "values_doubles(array, ...)",
682
+ "int values_doubles_into(double *destination,\n const double *items, size_t count,\n size_t capacity);"
683
+ ],
684
+ "advancedSignatures": [
685
+ "int values_doubles_into(double *destination,\n const double *items, size_t count,\n size_t capacity);"
686
+ ],
687
+ "note": "",
688
+ "example": "double a[10];\nint n = values_doubles(a, 4, 1, 3);"
689
+ }
690
+ ],
691
+ "commonSignatures": []
692
+ },
693
+ {
694
+ "id": "range_arrays",
695
+ "title": "生成整数等差序列",
696
+ "description": "从 first 开始,每次增加 step,遇到或越过 stop 时停止(不含 stop)。step 不为 0,可为负。返回写入项数,容量须足够。",
697
+ "keywords": [],
698
+ "related": [],
699
+ "advancedSignatures": [],
700
+ "signatures": [
701
+ "range_ints(array, first, stop, step)",
702
+ "int range_ints_into(int *destination, int first, int stop,\n int step, size_t capacity);",
703
+ "range_lls(array, first, stop, step)",
704
+ "int range_lls_into(long long *destination,\n long long first, long long stop,\n long long step, size_t capacity);"
705
+ ],
706
+ "example": "int a[10];\nint n = range_ints(a, 1, 8, 2); // 1, 3, 5, 7",
707
+ "variants": [
708
+ {
709
+ "key": "int",
710
+ "label": "int",
711
+ "symbols": [
712
+ "range_ints",
713
+ "range_ints_into"
714
+ ],
715
+ "signatures": [
716
+ "range_ints(array, first, stop, step)",
717
+ "int range_ints_into(int *destination, int first, int stop,\n int step, size_t capacity);"
718
+ ],
719
+ "advancedSignatures": [
720
+ "int range_ints_into(int *destination, int first, int stop,\n int step, size_t capacity);"
721
+ ],
722
+ "note": "",
723
+ "example": "int a[10];\nint n = range_ints(a, 1, 8, 2); // 1, 3, 5, 7"
724
+ },
725
+ {
726
+ "key": "ll",
727
+ "label": "long long",
728
+ "symbols": [
729
+ "range_lls",
730
+ "range_lls_into"
731
+ ],
732
+ "signatures": [
733
+ "range_lls(array, first, stop, step)",
734
+ "int range_lls_into(long long *destination,\n long long first, long long stop,\n long long step, size_t capacity);"
735
+ ],
736
+ "advancedSignatures": [
737
+ "int range_lls_into(long long *destination,\n long long first, long long stop,\n long long step, size_t capacity);"
738
+ ],
739
+ "note": "",
740
+ "example": "long long a[10];\nint n = range_lls(a, 1, 8, 2); // 1, 3, 5, 7"
741
+ }
742
+ ],
743
+ "commonSignatures": []
744
+ },
745
+ {
746
+ "id": "reverse_arrays",
747
+ "title": "反转数组",
748
+ "description": "原地反转前 n 项。",
749
+ "keywords": [],
750
+ "related": [],
751
+ "advancedSignatures": [],
752
+ "signatures": [
753
+ "void reverse_ints(int *array, int n);",
754
+ "void reverse_lls(long long *a,int n);",
755
+ "void reverse_doubles(double *a,int n);"
756
+ ],
757
+ "example": "int a[] = {3, 1, 3, 2};\nreverse_ints(a, 4);",
758
+ "variants": [
759
+ {
760
+ "key": "int",
761
+ "label": "int",
762
+ "symbols": [
763
+ "reverse_ints"
764
+ ],
765
+ "signatures": [
766
+ "void reverse_ints(int *array, int n);"
767
+ ],
768
+ "advancedSignatures": [],
769
+ "note": "",
770
+ "example": "int a[] = {3, 1, 3, 2};\nreverse_ints(a, 4);"
771
+ },
772
+ {
773
+ "key": "ll",
774
+ "label": "long long",
775
+ "symbols": [
776
+ "reverse_lls"
777
+ ],
778
+ "signatures": [
779
+ "void reverse_lls(long long *a,int n);"
780
+ ],
781
+ "advancedSignatures": [],
782
+ "note": "",
783
+ "example": "long long a[] = {3, 1, 3, 2};\nreverse_lls(a, 4);"
784
+ },
785
+ {
786
+ "key": "double",
787
+ "label": "double",
788
+ "symbols": [
789
+ "reverse_doubles"
790
+ ],
791
+ "signatures": [
792
+ "void reverse_doubles(double *a,int n);"
793
+ ],
794
+ "advancedSignatures": [],
795
+ "note": "",
796
+ "example": "double a[] = {3, 1, 3, 2};\nreverse_doubles(a, 4);"
797
+ }
798
+ ],
799
+ "commonSignatures": []
800
+ },
801
+ {
802
+ "id": "swap_ints",
803
+ "title": "交换两项",
804
+ "description": "交换下标 i、j 对应的两个 int 元素。调用者保证下标有效。",
805
+ "keywords": [],
806
+ "related": [],
807
+ "advancedSignatures": [],
808
+ "signatures": [
809
+ "void swap_ints(int *array, int i, int j);"
810
+ ],
811
+ "example": "int a[] = {1, 2, 3};\nswap_ints(a, 0, 2);"
812
+ },
813
+ {
814
+ "id": "sort_arrays",
815
+ "title": "数组排序",
816
+ "description": "原地排序前 n 项。第一个接口升序,第二个接口降序。",
817
+ "keywords": [],
818
+ "related": [],
819
+ "advancedSignatures": [],
820
+ "signatures": [
821
+ "void sort_ints(int *a, int n);",
822
+ "void sort_ints_desc(int *a, int n);",
823
+ "void sort_lls(long long *a,int n);",
824
+ "void sort_lls_desc(long long *a, int n);",
825
+ "void sort_doubles(double *a,int n);",
826
+ "void sort_doubles_desc(double *a, int n);"
827
+ ],
828
+ "example": "int a[] = {3, 1, 3, 2};\nsort_ints(a, 4);\nsort_ints_desc(a, 4);",
829
+ "variants": [
830
+ {
831
+ "key": "int",
832
+ "label": "int",
833
+ "symbols": [
834
+ "sort_ints",
835
+ "sort_ints_desc"
836
+ ],
837
+ "signatures": [
838
+ "void sort_ints(int *a, int n);",
839
+ "void sort_ints_desc(int *a, int n);"
840
+ ],
841
+ "advancedSignatures": [],
842
+ "note": "",
843
+ "example": "int a[] = {3, 1, 3, 2};\nsort_ints(a, 4);\nsort_ints_desc(a, 4);"
844
+ },
845
+ {
846
+ "key": "ll",
847
+ "label": "long long",
848
+ "symbols": [
849
+ "sort_lls",
850
+ "sort_lls_desc"
851
+ ],
852
+ "signatures": [
853
+ "void sort_lls(long long *a,int n);",
854
+ "void sort_lls_desc(long long *a, int n);"
855
+ ],
856
+ "advancedSignatures": [],
857
+ "note": "",
858
+ "example": "long long a[] = {3, 1, 3, 2};\nsort_lls(a, 4);\nsort_lls_desc(a, 4);"
859
+ },
860
+ {
861
+ "key": "double",
862
+ "label": "double",
863
+ "symbols": [
864
+ "sort_doubles",
865
+ "sort_doubles_desc"
866
+ ],
867
+ "signatures": [
868
+ "void sort_doubles(double *a,int n);",
869
+ "void sort_doubles_desc(double *a, int n);"
870
+ ],
871
+ "advancedSignatures": [],
872
+ "note": "不接受 NaN 和无穷大。",
873
+ "example": "double a[] = {3, 1, 3, 2};\nsort_doubles(a, 4);\nsort_doubles_desc(a, 4);"
874
+ }
875
+ ],
876
+ "commonSignatures": []
877
+ },
878
+ {
879
+ "id": "bubble_sort_ints",
880
+ "title": "冒泡排序",
881
+ "description": "对 int 数组原地升序冒泡排序,时间 O(n²)。普通排序优先使用 sort_ints。",
882
+ "keywords": [],
883
+ "related": [
884
+ "sort_arrays"
885
+ ],
886
+ "advancedSignatures": [],
887
+ "signatures": [
888
+ "void bubble_sort_ints(int *a, int n);"
889
+ ],
890
+ "example": "int a[] = {3, 1, 2};\nbubble_sort_ints(a, 3);"
891
+ },
892
+ {
893
+ "id": "argsort_ints",
894
+ "title": "间接排序(原下标)",
895
+ "description": "不修改 a,把升序排列对应的原下标写入 order;相等值按原下标排序。order 至少 n 项,不能与 a 重叠。",
896
+ "keywords": [],
897
+ "related": [
898
+ "sort_arrays"
899
+ ],
900
+ "advancedSignatures": [
901
+ "void argsort_ints_into(const int *a, int n, int *order,\n size_t capacity);"
902
+ ],
903
+ "signatures": [
904
+ "argsort_ints(a, n, order)",
905
+ "void argsort_ints_into(const int *a, int n, int *order,\n size_t capacity);"
906
+ ],
907
+ "example": "int a[] = {8, 3, 8, 2}, order[4];\nargsort_ints(a, 4, order); // 3, 1, 0, 2"
908
+ },
909
+ {
910
+ "id": "unique_arrays",
911
+ "title": "数组去重",
912
+ "description": "原地去重并返回新长度,只使用数组前新长度项。第一种保持首次出现顺序(O(n²));第二种要求已经排序(O(n))。",
913
+ "keywords": [],
914
+ "related": [],
915
+ "advancedSignatures": [],
916
+ "signatures": [
917
+ "int unique_ints(int *a, int n);",
918
+ "int unique_sorted_ints(int *a, int n);",
919
+ "int unique_lls(long long *a, int n);",
920
+ "int unique_sorted_lls(long long *a, int n);",
921
+ "int unique_doubles(double *a, int n);",
922
+ "int unique_sorted_doubles(double *a, int n);"
923
+ ],
924
+ "example": "int a[] = {3, 1, 3, 2};\nint n = unique_ints(a, 4);\n// n = 3",
925
+ "variants": [
926
+ {
927
+ "key": "int",
928
+ "label": "int",
929
+ "symbols": [
930
+ "unique_ints",
931
+ "unique_sorted_ints"
932
+ ],
933
+ "signatures": [
934
+ "int unique_ints(int *a, int n);",
935
+ "int unique_sorted_ints(int *a, int n);"
936
+ ],
937
+ "advancedSignatures": [],
938
+ "note": "",
939
+ "example": "int a[] = {3, 1, 3, 2};\nint n = unique_ints(a, 4);\n// n = 3"
940
+ },
941
+ {
942
+ "key": "ll",
943
+ "label": "long long",
944
+ "symbols": [
945
+ "unique_lls",
946
+ "unique_sorted_lls"
947
+ ],
948
+ "signatures": [
949
+ "int unique_lls(long long *a, int n);",
950
+ "int unique_sorted_lls(long long *a, int n);"
951
+ ],
952
+ "advancedSignatures": [],
953
+ "note": "",
954
+ "example": "long long a[] = {3, 1, 3, 2};\nint n = unique_lls(a, 4);\n// n = 3"
955
+ },
956
+ {
957
+ "key": "double",
958
+ "label": "double",
959
+ "symbols": [
960
+ "unique_doubles",
961
+ "unique_sorted_doubles"
962
+ ],
963
+ "signatures": [
964
+ "int unique_doubles(double *a, int n);",
965
+ "int unique_sorted_doubles(double *a, int n);"
966
+ ],
967
+ "advancedSignatures": [],
968
+ "note": "按精确相等去重,不接受 NaN 和无穷大。",
969
+ "example": "double a[] = {3, 1, 3, 2};\nint n = unique_doubles(a, 4);\n// n = 3"
970
+ }
971
+ ],
972
+ "commonSignatures": []
973
+ },
974
+ {
975
+ "id": "find_arrays",
976
+ "title": "查找首次出现位置",
977
+ "description": "无需排序,返回第一次出现的 0 基下标;不存在返回 -1,O(n)。",
978
+ "keywords": [],
979
+ "related": [],
980
+ "advancedSignatures": [],
981
+ "signatures": [
982
+ "int find_ints(const int *a, int n, int key);",
983
+ "int find_lls(const long long *a,int n,long long key);",
984
+ "int find_doubles(const double *a,int n,double key);"
985
+ ],
986
+ "example": "int a[] = {3, 1, 3, 2};\nint i = find_ints(a, 4, 3); // 0",
987
+ "variants": [
988
+ {
989
+ "key": "int",
990
+ "label": "int",
991
+ "symbols": [
992
+ "find_ints"
993
+ ],
994
+ "signatures": [
995
+ "int find_ints(const int *a, int n, int key);"
996
+ ],
997
+ "advancedSignatures": [],
998
+ "note": "",
999
+ "example": "int a[] = {3, 1, 3, 2};\nint i = find_ints(a, 4, 3); // 0"
1000
+ },
1001
+ {
1002
+ "key": "ll",
1003
+ "label": "long long",
1004
+ "symbols": [
1005
+ "find_lls"
1006
+ ],
1007
+ "signatures": [
1008
+ "int find_lls(const long long *a,int n,long long key);"
1009
+ ],
1010
+ "advancedSignatures": [],
1011
+ "note": "",
1012
+ "example": "long long a[] = {3, 1, 3, 2};\nint i = find_lls(a, 4, 3); // 0"
1013
+ },
1014
+ {
1015
+ "key": "double",
1016
+ "label": "double",
1017
+ "symbols": [
1018
+ "find_doubles"
1019
+ ],
1020
+ "signatures": [
1021
+ "int find_doubles(const double *a,int n,double key);"
1022
+ ],
1023
+ "advancedSignatures": [],
1024
+ "note": "浮点相等按精确相等判断。",
1025
+ "example": "double a[] = {3, 1, 3, 2};\nint i = find_doubles(a, 4, 3); // 0"
1026
+ }
1027
+ ],
1028
+ "commonSignatures": []
1029
+ },
1030
+ {
1031
+ "id": "linear_search_ints",
1032
+ "title": "线性查找(int)",
1033
+ "description": "与 find_ints 行为一致:无需排序,返回首次匹配下标或 -1。",
1034
+ "keywords": [],
1035
+ "related": [
1036
+ "find_arrays"
1037
+ ],
1038
+ "advancedSignatures": [],
1039
+ "signatures": [
1040
+ "int linear_search_ints(const int *a, int n, int key);"
1041
+ ],
1042
+ "example": "int a[] = {3, 1, 3};\nint i = linear_search_ints(a, 3, 3);"
1043
+ },
1044
+ {
1045
+ "id": "binary_search_arrays",
1046
+ "title": "在升序数组中查找",
1047
+ "description": "要求数组升序。binary_search 返回首次匹配下标或 -1;lower_bound 返回首个 >= key 的位置;upper_bound 返回首个 > key 的位置,后两者无满足项时返回 n。O(log n)。",
1048
+ "keywords": [],
1049
+ "related": [],
1050
+ "advancedSignatures": [],
1051
+ "signatures": [
1052
+ "int binary_search_ints(const int *a, int n, int key);",
1053
+ "int lower_bound_ints(const int *a, int n, int key);",
1054
+ "int upper_bound_ints(const int *a, int n, int key);",
1055
+ "int binary_search_lls(const long long *a, int n,\n long long key);",
1056
+ "int lower_bound_lls(const long long *a,int n,long long key);",
1057
+ "int upper_bound_lls(const long long *a,int n,long long key);",
1058
+ "int binary_search_doubles(const double *a, int n, double key);",
1059
+ "int lower_bound_doubles(const double *a,int n,double key);",
1060
+ "int upper_bound_doubles(const double *a,int n,double key);"
1061
+ ],
1062
+ "example": "int a[] = {1, 3, 3, 5};\nint i = binary_search_ints(a, 4, 3); // 1\nint l = lower_bound_ints(a, 4, 3); // 1\nint r = upper_bound_ints(a, 4, 3); // 3",
1063
+ "variants": [
1064
+ {
1065
+ "key": "int",
1066
+ "label": "int",
1067
+ "symbols": [
1068
+ "binary_search_ints",
1069
+ "lower_bound_ints",
1070
+ "upper_bound_ints"
1071
+ ],
1072
+ "signatures": [
1073
+ "int binary_search_ints(const int *a, int n, int key);",
1074
+ "int lower_bound_ints(const int *a, int n, int key);",
1075
+ "int upper_bound_ints(const int *a, int n, int key);"
1076
+ ],
1077
+ "advancedSignatures": [],
1078
+ "note": "",
1079
+ "example": "int a[] = {1, 3, 3, 5};\nint i = binary_search_ints(a, 4, 3); // 1\nint l = lower_bound_ints(a, 4, 3); // 1\nint r = upper_bound_ints(a, 4, 3); // 3"
1080
+ },
1081
+ {
1082
+ "key": "ll",
1083
+ "label": "long long",
1084
+ "symbols": [
1085
+ "binary_search_lls",
1086
+ "lower_bound_lls",
1087
+ "upper_bound_lls"
1088
+ ],
1089
+ "signatures": [
1090
+ "int binary_search_lls(const long long *a, int n,\n long long key);",
1091
+ "int lower_bound_lls(const long long *a,int n,long long key);",
1092
+ "int upper_bound_lls(const long long *a,int n,long long key);"
1093
+ ],
1094
+ "advancedSignatures": [],
1095
+ "note": "",
1096
+ "example": "long long a[] = {1, 3, 3, 5};\nint i = binary_search_lls(a, 4, 3); // 1\nint l = lower_bound_lls(a, 4, 3); // 1\nint r = upper_bound_lls(a, 4, 3); // 3"
1097
+ },
1098
+ {
1099
+ "key": "double",
1100
+ "label": "double",
1101
+ "symbols": [
1102
+ "binary_search_doubles",
1103
+ "lower_bound_doubles",
1104
+ "upper_bound_doubles"
1105
+ ],
1106
+ "signatures": [
1107
+ "int binary_search_doubles(const double *a, int n, double key);",
1108
+ "int lower_bound_doubles(const double *a,int n,double key);",
1109
+ "int upper_bound_doubles(const double *a,int n,double key);"
1110
+ ],
1111
+ "advancedSignatures": [],
1112
+ "note": "使用精确比较;数组需按相同规则升序排列。",
1113
+ "example": "double a[] = {1, 3, 3, 5};\nint i = binary_search_doubles(a, 4, 3); // 1\nint l = lower_bound_doubles(a, 4, 3); // 1\nint r = upper_bound_doubles(a, 4, 3); // 3"
1114
+ }
1115
+ ],
1116
+ "commonSignatures": []
1117
+ },
1118
+ {
1119
+ "id": "sum_mean_arrays",
1120
+ "title": "求和与平均值",
1121
+ "description": "求前 n 项之和与算术平均数。平均值要求 n > 0。整数求和返回 long long,浮点求和返回 double;平均值返回 double。",
1122
+ "keywords": [],
1123
+ "related": [],
1124
+ "advancedSignatures": [],
1125
+ "signatures": [
1126
+ "long long sum_ints(const int *a, int n);",
1127
+ "double mean_ints(const int *a, int n);",
1128
+ "long long sum_lls(const long long *a,int n);",
1129
+ "double mean_lls(const long long *a, int n);",
1130
+ "double sum_doubles(const double *a,int n);",
1131
+ "double mean_doubles(const double *a,int n);"
1132
+ ],
1133
+ "example": "int a[] = {3, 1, 3, 2};\nsum_ints(a, 4);\ndouble avg = mean_ints(a, 4);",
1134
+ "variants": [
1135
+ {
1136
+ "key": "int",
1137
+ "label": "int",
1138
+ "symbols": [
1139
+ "sum_ints",
1140
+ "mean_ints"
1141
+ ],
1142
+ "signatures": [
1143
+ "long long sum_ints(const int *a, int n);",
1144
+ "double mean_ints(const int *a, int n);"
1145
+ ],
1146
+ "advancedSignatures": [],
1147
+ "note": "",
1148
+ "example": "int a[] = {3, 1, 3, 2};\nsum_ints(a, 4);\ndouble avg = mean_ints(a, 4);"
1149
+ },
1150
+ {
1151
+ "key": "ll",
1152
+ "label": "long long",
1153
+ "symbols": [
1154
+ "sum_lls",
1155
+ "mean_lls"
1156
+ ],
1157
+ "signatures": [
1158
+ "long long sum_lls(const long long *a,int n);",
1159
+ "double mean_lls(const long long *a, int n);"
1160
+ ],
1161
+ "advancedSignatures": [],
1162
+ "note": "",
1163
+ "example": "long long a[] = {3, 1, 3, 2};\nsum_lls(a, 4);\ndouble avg = mean_lls(a, 4);"
1164
+ },
1165
+ {
1166
+ "key": "double",
1167
+ "label": "double",
1168
+ "symbols": [
1169
+ "sum_doubles",
1170
+ "mean_doubles"
1171
+ ],
1172
+ "signatures": [
1173
+ "double sum_doubles(const double *a,int n);",
1174
+ "double mean_doubles(const double *a,int n);"
1175
+ ],
1176
+ "advancedSignatures": [],
1177
+ "note": "统计不接受 NaN 和无穷大。",
1178
+ "example": "double a[] = {3, 1, 3, 2};\nsum_doubles(a, 4);\ndouble avg = mean_doubles(a, 4);"
1179
+ }
1180
+ ],
1181
+ "commonSignatures": []
1182
+ },
1183
+ {
1184
+ "id": "extrema_arrays",
1185
+ "title": "最大值与最小值",
1186
+ "description": "n 必须大于 0。min/max 返回值,argmin/argmax 返回首次出现的下标。",
1187
+ "keywords": [],
1188
+ "related": [],
1189
+ "advancedSignatures": [],
1190
+ "signatures": [
1191
+ "int min_ints(const int *a, int n);",
1192
+ "int max_ints(const int *a, int n);",
1193
+ "int argmin_ints(const int *a, int n);",
1194
+ "int argmax_ints(const int *a, int n);",
1195
+ "long long min_lls(const long long *a,int n);",
1196
+ "long long max_lls(const long long *a,int n);",
1197
+ "int argmin_lls(const long long *a, int n);",
1198
+ "int argmax_lls(const long long *a, int n);",
1199
+ "double min_doubles(const double *a,int n);",
1200
+ "double max_doubles(const double *a,int n);",
1201
+ "int argmin_doubles(const double *a, int n);",
1202
+ "int argmax_doubles(const double *a, int n);"
1203
+ ],
1204
+ "example": "int a[] = {3, 1, 3, 2};\nint lo = min_ints(a, 4), hi = max_ints(a, 4);\nint i = argmin_ints(a, 4), j = argmax_ints(a, 4);",
1205
+ "variants": [
1206
+ {
1207
+ "key": "int",
1208
+ "label": "int",
1209
+ "symbols": [
1210
+ "min_ints",
1211
+ "max_ints",
1212
+ "argmin_ints",
1213
+ "argmax_ints"
1214
+ ],
1215
+ "signatures": [
1216
+ "int min_ints(const int *a, int n);",
1217
+ "int max_ints(const int *a, int n);",
1218
+ "int argmin_ints(const int *a, int n);",
1219
+ "int argmax_ints(const int *a, int n);"
1220
+ ],
1221
+ "advancedSignatures": [],
1222
+ "note": "",
1223
+ "example": "int a[] = {3, 1, 3, 2};\nint lo = min_ints(a, 4), hi = max_ints(a, 4);\nint i = argmin_ints(a, 4), j = argmax_ints(a, 4);"
1224
+ },
1225
+ {
1226
+ "key": "ll",
1227
+ "label": "long long",
1228
+ "symbols": [
1229
+ "min_lls",
1230
+ "max_lls",
1231
+ "argmin_lls",
1232
+ "argmax_lls"
1233
+ ],
1234
+ "signatures": [
1235
+ "long long min_lls(const long long *a,int n);",
1236
+ "long long max_lls(const long long *a,int n);",
1237
+ "int argmin_lls(const long long *a, int n);",
1238
+ "int argmax_lls(const long long *a, int n);"
1239
+ ],
1240
+ "advancedSignatures": [],
1241
+ "note": "",
1242
+ "example": "long long a[] = {3, 1, 3, 2};\nlong long lo = min_lls(a, 4), hi = max_lls(a, 4);\nint i = argmin_lls(a, 4), j = argmax_lls(a, 4);"
1243
+ },
1244
+ {
1245
+ "key": "double",
1246
+ "label": "double",
1247
+ "symbols": [
1248
+ "min_doubles",
1249
+ "max_doubles",
1250
+ "argmin_doubles",
1251
+ "argmax_doubles"
1252
+ ],
1253
+ "signatures": [
1254
+ "double min_doubles(const double *a,int n);",
1255
+ "double max_doubles(const double *a,int n);",
1256
+ "int argmin_doubles(const double *a, int n);",
1257
+ "int argmax_doubles(const double *a, int n);"
1258
+ ],
1259
+ "advancedSignatures": [],
1260
+ "note": "统计不接受 NaN 和无穷大。",
1261
+ "example": "double a[] = {3, 1, 3, 2};\ndouble lo = min_doubles(a, 4), hi = max_doubles(a, 4);\nint i = argmin_doubles(a, 4), j = argmax_doubles(a, 4);"
1262
+ }
1263
+ ],
1264
+ "commonSignatures": []
1265
+ },
1266
+ {
1267
+ "id": "variance_arrays",
1268
+ "title": "方差与标准差",
1269
+ "description": "计算总体方差(除以 n)和标准差,n > 0,返回 double。",
1270
+ "keywords": [],
1271
+ "related": [],
1272
+ "advancedSignatures": [],
1273
+ "signatures": [
1274
+ "double variance_ints(const int *a, int n);",
1275
+ "double stddev_ints(const int *a, int n);",
1276
+ "double variance_lls(const long long *a, int n);",
1277
+ "double stddev_lls(const long long *a, int n);",
1278
+ "double variance_doubles(const double *a, int n);",
1279
+ "double stddev_doubles(const double *a, int n);"
1280
+ ],
1281
+ "example": "int a[] = {3, 1, 3, 2};\ndouble v = variance_ints(a, 4);\ndouble s = stddev_ints(a, 4);",
1282
+ "variants": [
1283
+ {
1284
+ "key": "int",
1285
+ "label": "int",
1286
+ "symbols": [
1287
+ "variance_ints",
1288
+ "stddev_ints"
1289
+ ],
1290
+ "signatures": [
1291
+ "double variance_ints(const int *a, int n);",
1292
+ "double stddev_ints(const int *a, int n);"
1293
+ ],
1294
+ "advancedSignatures": [],
1295
+ "note": "",
1296
+ "example": "int a[] = {3, 1, 3, 2};\ndouble v = variance_ints(a, 4);\ndouble s = stddev_ints(a, 4);"
1297
+ },
1298
+ {
1299
+ "key": "ll",
1300
+ "label": "long long",
1301
+ "symbols": [
1302
+ "variance_lls",
1303
+ "stddev_lls"
1304
+ ],
1305
+ "signatures": [
1306
+ "double variance_lls(const long long *a, int n);",
1307
+ "double stddev_lls(const long long *a, int n);"
1308
+ ],
1309
+ "advancedSignatures": [],
1310
+ "note": "",
1311
+ "example": "long long a[] = {3, 1, 3, 2};\ndouble v = variance_lls(a, 4);\ndouble s = stddev_lls(a, 4);"
1312
+ },
1313
+ {
1314
+ "key": "double",
1315
+ "label": "double",
1316
+ "symbols": [
1317
+ "variance_doubles",
1318
+ "stddev_doubles"
1319
+ ],
1320
+ "signatures": [
1321
+ "double variance_doubles(const double *a, int n);",
1322
+ "double stddev_doubles(const double *a, int n);"
1323
+ ],
1324
+ "advancedSignatures": [],
1325
+ "note": "",
1326
+ "example": "double a[] = {3, 1, 3, 2};\ndouble v = variance_doubles(a, 4);\ndouble s = stddev_doubles(a, 4);"
1327
+ }
1328
+ ],
1329
+ "commonSignatures": []
1330
+ },
1331
+ {
1332
+ "id": "median_arrays",
1333
+ "title": "中位数",
1334
+ "description": "返回中位数,偶数项取中间两项平均;n > 0,不改变原数组。",
1335
+ "keywords": [],
1336
+ "related": [],
1337
+ "advancedSignatures": [],
1338
+ "signatures": [
1339
+ "double median_ints(const int *a, int n);",
1340
+ "double median_lls(const long long *a, int n);",
1341
+ "double median_doubles(const double *a, int n);"
1342
+ ],
1343
+ "example": "int a[] = {3, 1, 3, 2};\ndouble m = median_ints(a, 4);",
1344
+ "variants": [
1345
+ {
1346
+ "key": "int",
1347
+ "label": "int",
1348
+ "symbols": [
1349
+ "median_ints"
1350
+ ],
1351
+ "signatures": [
1352
+ "double median_ints(const int *a, int n);"
1353
+ ],
1354
+ "advancedSignatures": [],
1355
+ "note": "",
1356
+ "example": "int a[] = {3, 1, 3, 2};\ndouble m = median_ints(a, 4);"
1357
+ },
1358
+ {
1359
+ "key": "ll",
1360
+ "label": "long long",
1361
+ "symbols": [
1362
+ "median_lls"
1363
+ ],
1364
+ "signatures": [
1365
+ "double median_lls(const long long *a, int n);"
1366
+ ],
1367
+ "advancedSignatures": [],
1368
+ "note": "",
1369
+ "example": "long long a[] = {3, 1, 3, 2};\ndouble m = median_lls(a, 4);"
1370
+ },
1371
+ {
1372
+ "key": "double",
1373
+ "label": "double",
1374
+ "symbols": [
1375
+ "median_doubles"
1376
+ ],
1377
+ "signatures": [
1378
+ "double median_doubles(const double *a, int n);"
1379
+ ],
1380
+ "advancedSignatures": [],
1381
+ "note": "",
1382
+ "example": "double a[] = {3, 1, 3, 2};\ndouble m = median_doubles(a, 4);"
1383
+ }
1384
+ ],
1385
+ "commonSignatures": []
1386
+ },
1387
+ {
1388
+ "id": "count_arrays",
1389
+ "title": "统计出现次数",
1390
+ "description": "无需排序,返回 key 在前 n 项出现的次数。",
1391
+ "keywords": [],
1392
+ "related": [],
1393
+ "advancedSignatures": [],
1394
+ "signatures": [
1395
+ "int count_ints(const int *a, int n, int key);",
1396
+ "int count_lls(const long long *a, int n, long long key);",
1397
+ "int count_doubles(const double *a, int n, double key);"
1398
+ ],
1399
+ "example": "int a[] = {3, 1, 3, 2};\nint count = count_ints(a, 4, 3); // 2",
1400
+ "variants": [
1401
+ {
1402
+ "key": "int",
1403
+ "label": "int",
1404
+ "symbols": [
1405
+ "count_ints"
1406
+ ],
1407
+ "signatures": [
1408
+ "int count_ints(const int *a, int n, int key);"
1409
+ ],
1410
+ "advancedSignatures": [],
1411
+ "note": "",
1412
+ "example": "int a[] = {3, 1, 3, 2};\nint count = count_ints(a, 4, 3); // 2"
1413
+ },
1414
+ {
1415
+ "key": "ll",
1416
+ "label": "long long",
1417
+ "symbols": [
1418
+ "count_lls"
1419
+ ],
1420
+ "signatures": [
1421
+ "int count_lls(const long long *a, int n, long long key);"
1422
+ ],
1423
+ "advancedSignatures": [],
1424
+ "note": "",
1425
+ "example": "long long a[] = {3, 1, 3, 2};\nint count = count_lls(a, 4, 3); // 2"
1426
+ },
1427
+ {
1428
+ "key": "double",
1429
+ "label": "double",
1430
+ "symbols": [
1431
+ "count_doubles"
1432
+ ],
1433
+ "signatures": [
1434
+ "int count_doubles(const double *a, int n, double key);"
1435
+ ],
1436
+ "advancedSignatures": [],
1437
+ "note": "浮点相等按精确相等判断。",
1438
+ "example": "double a[] = {3, 1, 3, 2};\nint count = count_doubles(a, 4, 3); // 2"
1439
+ }
1440
+ ],
1441
+ "commonSignatures": []
1442
+ },
1443
+ {
1444
+ "id": "frequency_ints",
1445
+ "title": "统计频数",
1446
+ "description": "统计整数 0..max_value 出现的次数,freq 至少 max_value+1 项;函数初始化计数数组。",
1447
+ "keywords": [],
1448
+ "related": [],
1449
+ "advancedSignatures": [
1450
+ "void frequency_ints_into(const int *values, int n,\n int *frequency, int max_value,\n size_t capacity);"
1451
+ ],
1452
+ "signatures": [
1453
+ "frequency_ints(values,n,frequency,max_value)",
1454
+ "void frequency_ints_into(const int *values, int n,\n int *frequency, int max_value,\n size_t capacity);"
1455
+ ],
1456
+ "example": "int a[] = {1, 2, 1, 3}, freq[4];\nfrequency_ints(a, 4, freq, 3); // 0, 2, 1, 1"
1457
+ },
1458
+ {
1459
+ "id": "longest_runs",
1460
+ "title": "最长连续段",
1461
+ "description": "分别返回最长相等连续段和逐项增加 1 的连续段长度。",
1462
+ "keywords": [],
1463
+ "related": [],
1464
+ "advancedSignatures": [],
1465
+ "signatures": [
1466
+ "int longest_equal_run_ints(const int *a, int n);",
1467
+ "int longest_plus_one_run_ints(const int *a, int n);"
1468
+ ],
1469
+ "example": "int a[] = {1, 1, 1, 2, 3};\nint eq = longest_equal_run_ints(a, 5); // 3\nint inc = longest_plus_one_run_ints(a, 5); // 3"
1470
+ },
1471
+ {
1472
+ "id": "max_subarray_sum_ints",
1473
+ "title": "最大连续子段和",
1474
+ "description": "返回最大非空连续子段和,n > 0。",
1475
+ "keywords": [],
1476
+ "related": [],
1477
+ "advancedSignatures": [],
1478
+ "signatures": [
1479
+ "long long max_subarray_sum_ints(const int *a, int n);"
1480
+ ],
1481
+ "example": "int a[] = {-2, 3, 4, -1};\nlong long s = max_subarray_sum_ints(a, 4); // 7"
1482
+ },
1483
+ {
1484
+ "id": "max_forward_diff_ints",
1485
+ "title": "前项减后项的最大差",
1486
+ "description": "求 i < j 时 a[i] - a[j] 的最大值,至少两项。",
1487
+ "keywords": [],
1488
+ "related": [],
1489
+ "advancedSignatures": [],
1490
+ "signatures": [
1491
+ "long long max_forward_diff_ints(const int *a, int n);"
1492
+ ],
1493
+ "example": "int a[] = {5, 2, 4};\nlong long d = max_forward_diff_ints(a, 3); // 3"
1494
+ },
1495
+ {
1496
+ "id": "prefix_sum",
1497
+ "title": "多次区间求和(前缀和)",
1498
+ "description": "先建表,再查询 [l,r)(不含 r)。n 须非负,prefix 指向至少 n+1 项的 long long 数组。n 大于 0 时输入数组也不能为空指针。容量不足会显示实际容量和所需的元素数。建表 O(n),单次查询 O(1)。",
1499
+ "keywords": [],
1500
+ "related": [
1501
+ "difference_array"
1502
+ ],
1503
+ "advancedSignatures": [
1504
+ "void build_prefix_ints_into(const int *a, int n, long long *prefix,\n size_t capacity);"
1505
+ ],
1506
+ "signatures": [
1507
+ "build_prefix_ints(a, n, prefix)",
1508
+ "long long prefix_range_sum(const long long *prefix, int begin,\n int end);",
1509
+ "void build_prefix_ints_into(const int *a, int n, long long *prefix,\n size_t capacity);"
1510
+ ],
1511
+ "example": "int a[] = {2, 4, 6, 8};\nlong long prefix[5];\nbuild_prefix_ints(a, 4, prefix);\nlong long s = prefix_range_sum(prefix, 1, 3); // 10"
1512
+ },
1513
+ {
1514
+ "id": "difference_array",
1515
+ "title": "多次区间加值(差分)",
1516
+ "description": "差分表至少 n+1 项 long long。先建表,再对 [l,r) 加 delta,最后还原到 n 项 long long 数组。区间更新 O(1)。",
1517
+ "keywords": [],
1518
+ "related": [
1519
+ "prefix_sum"
1520
+ ],
1521
+ "advancedSignatures": [
1522
+ "void build_diff_ints_into(const int *a, int n,\n long long *difference, size_t capacity);",
1523
+ "void diff_to_lls_into(const long long *difference, int n,\n long long *out, size_t capacity);"
1524
+ ],
1525
+ "signatures": [
1526
+ "build_diff_ints(a,n,difference)",
1527
+ "void diff_range_add(long long *difference, int n,\n int begin, int end, long long delta);",
1528
+ "diff_to_lls(difference,n,out)",
1529
+ "void build_diff_ints_into(const int *a, int n,\n long long *difference, size_t capacity);",
1530
+ "void diff_to_lls_into(const long long *difference, int n,\n long long *out, size_t capacity);"
1531
+ ],
1532
+ "example": "int a[] = {2, 4, 6, 8};\nlong long diff[5], out[4];\nbuild_diff_ints(a, 4, diff);\ndiff_range_add(diff, 4, 1, 3, 10);\ndiff_to_lls(diff, 4, out); // 2, 14, 16, 8"
1533
+ },
1534
+ {
1535
+ "id": "record_type",
1536
+ "title": "定义结构体与比较函数",
1537
+ "description": "保留题目原有的脚手架头文件引用,在其下方定义命名结构体 struct Record(不是匿名 typedef)。比较函数类型为 int compare(const Record *, const Record *);负数表示前者排前,0 表示相等,正数表示后者排前。",
1538
+ "keywords": [],
1539
+ "related": [
1540
+ "sort_records",
1541
+ "find_records_by"
1542
+ ],
1543
+ "advancedSignatures": [],
1544
+ "signatures": [
1545
+ "typedef struct Record Record;"
1546
+ ],
1547
+ "example": "struct Record { int id; };\nstatic int cmp(const Record *a, const Record *b) {\n return (a->id > b->id) - (a->id < b->id);\n}\nint main(void) {\n Record a[] = {{2}, {1}};\n sort_records(a, 2, cmp);\n return 0;\n}"
1548
+ },
1549
+ {
1550
+ "id": "sort_records",
1551
+ "title": "结构体排序",
1552
+ "description": "定义命名结构体 struct Record,再传入比较函数。负数表示 a 排在 b 前面,正数表示排在后面,0 表示相等。原地排序,不保证稳定,最坏 O(n log n)。",
1553
+ "keywords": [],
1554
+ "related": [
1555
+ "record_type",
1556
+ "find_records_by"
1557
+ ],
1558
+ "advancedSignatures": [],
1559
+ "signatures": [
1560
+ "sort_records(array, n, compare)"
1561
+ ],
1562
+ "example": "struct Record { int id; };\nstatic int cmp_id(const Record *a, const Record *b) {\n return (a->id > b->id) - (a->id < b->id);\n}\nint main(void) {\n Record a[] = {{3}, {1}, {2}};\n sort_records(a, 3, cmp_id);\n return 0;\n}"
1563
+ },
1564
+ {
1565
+ "id": "find_records_by",
1566
+ "title": "结构体查找",
1567
+ "description": "`find_records_by(a, n, &key, compare)` 按当前顺序扫描。`binary_search_records_by(a, n, &key, compare)` 要求数组已按 `compare` 排序。 两者返回首个匹配的下标,找不到返回 `-1`。比较函数接收数组元素和查找键,类型均为 `const Record *`。初始化比较函数会读到的所有字段。n 须非负;n 为 0 时返回 -1;n 大于 0 时,数组、键和比较函数都必须非空。排序与查找规则相同时,传入同一个比较函数。",
1568
+ "keywords": [],
1569
+ "related": [
1570
+ "record_type",
1571
+ "sort_records"
1572
+ ],
1573
+ "advancedSignatures": [],
1574
+ "signatures": [
1575
+ "find_records_by(array, n, key, compare)",
1576
+ "binary_search_records_by(array, n, key, compare)"
1577
+ ],
1578
+ "example": "struct Record { int id; };\nint record_cmp(const Record *a, const Record *b) {\n return (a->id > b->id) - (a->id < b->id);\n}\nint main(void) {\n Record a[] = {{30}, {10}, {30}};\n Record key = {30};\n print_int(find_records_by(a, 3, &key, record_cmp), \"\\n\"); // 0\n sort_records(a, 3, record_cmp);\n print_int(binary_search_records_by(a, 3, &key, record_cmp), \"\\n\"); // 1\n return 0;\n}"
1579
+ }
1580
+ ]
1581
+ },
1582
+ {
1583
+ "title": "字符串",
1584
+ "entries": [
1585
+ {
1586
+ "id": "str_reverse",
1587
+ "title": "反转字符串",
1588
+ "description": "原地反转字符串中的字节,不包含结尾的空字符。",
1589
+ "keywords": [],
1590
+ "related": [],
1591
+ "advancedSignatures": [],
1592
+ "signatures": [
1593
+ "void str_reverse(char *s);"
1594
+ ],
1595
+ "example": "char s[] = \"abc\";\nstr_reverse(s); // cba"
1596
+ },
1597
+ {
1598
+ "id": "str_case",
1599
+ "title": "大小写转换",
1600
+ "description": "原地转换英文字母大小写。",
1601
+ "keywords": [],
1602
+ "related": [],
1603
+ "advancedSignatures": [],
1604
+ "signatures": [
1605
+ "void str_lower(char *s);",
1606
+ "void str_upper(char *s);"
1607
+ ],
1608
+ "example": "char s[] = \"AbC\";\nstr_lower(s); // abc\nstr_upper(s); // ABC"
1609
+ },
1610
+ {
1611
+ "id": "str_trim",
1612
+ "title": "去除首尾空白",
1613
+ "description": "原地删除首尾空白,保留中间空白。",
1614
+ "keywords": [],
1615
+ "related": [],
1616
+ "advancedSignatures": [],
1617
+ "signatures": [
1618
+ "void str_trim(char *s);"
1619
+ ],
1620
+ "example": "char s[] = \" a b \";\nstr_trim(s); // a b"
1621
+ },
1622
+ {
1623
+ "id": "str_is_palindrome",
1624
+ "title": "判断回文",
1625
+ "description": "按字节比较首尾,返回是否为回文;区分大小写。",
1626
+ "keywords": [],
1627
+ "related": [],
1628
+ "advancedSignatures": [],
1629
+ "signatures": [
1630
+ "bool str_is_palindrome(const char *s);"
1631
+ ],
1632
+ "example": "bool ok = str_is_palindrome(\"abba\");"
1633
+ },
1634
+ {
1635
+ "id": "str_count_char",
1636
+ "title": "统计字符",
1637
+ "description": "返回指定字符出现的次数。",
1638
+ "keywords": [],
1639
+ "related": [],
1640
+ "advancedSignatures": [],
1641
+ "signatures": [
1642
+ "int str_count_char(const char *s, char key);"
1643
+ ],
1644
+ "example": "int n = str_count_char(\"banana\", 'a'); // 3"
1645
+ },
1646
+ {
1647
+ "id": "str_count_substr",
1648
+ "title": "统计子串",
1649
+ "description": "needle 是待匹配子串。overlapping 为 true 时允许重叠匹配,否则只统计不重叠匹配。",
1650
+ "keywords": [],
1651
+ "related": [],
1652
+ "advancedSignatures": [],
1653
+ "signatures": [
1654
+ "int str_count_substr(const char *s, const char *needle,\n bool overlapping);"
1655
+ ],
1656
+ "example": "int a = str_count_substr(\"aaaa\", \"aa\", true); // 3\nint b = str_count_substr(\"aaaa\", \"aa\", false); // 2"
1657
+ },
1658
+ {
1659
+ "id": "str_longest_char_run",
1660
+ "title": "最长连续字符",
1661
+ "description": "返回指定字符连续出现的最大长度。",
1662
+ "keywords": [],
1663
+ "related": [],
1664
+ "advancedSignatures": [],
1665
+ "signatures": [
1666
+ "int str_longest_char_run(const char *s, char target);"
1667
+ ],
1668
+ "example": "int n = str_longest_char_run(\"aaabba\", 'a'); // 3"
1669
+ },
1670
+ {
1671
+ "id": "str_insert",
1672
+ "title": "插入字符串",
1673
+ "description": "在下标 pos 前插入 text。pos 的范围是 0 到原长度,目标容量包含结束符,text 不能指向目标缓冲区。下标越界会显示允许范围,容量不足会显示目标容量和要拼接的字节数。",
1674
+ "keywords": [],
1675
+ "related": [],
1676
+ "advancedSignatures": [
1677
+ "void str_insert_into(char *s, int pos, const char *text,\n size_t capacity);"
1678
+ ],
1679
+ "signatures": [
1680
+ "str_insert(array, pos, text)",
1681
+ "void str_insert_into(char *s, int pos, const char *text,\n size_t capacity);"
1682
+ ],
1683
+ "example": "char s[20] = \"ac\";\nstr_insert(s, 1, \"b\"); // abc"
1684
+ },
1685
+ {
1686
+ "id": "str_erase",
1687
+ "title": "删除一段字符串",
1688
+ "description": "从下标 pos 起删除 count 个字符,范围必须在字符串内。原地修改。",
1689
+ "keywords": [],
1690
+ "related": [],
1691
+ "advancedSignatures": [],
1692
+ "signatures": [
1693
+ "void str_erase(char *s, int pos, int count);"
1694
+ ],
1695
+ "example": "char s[] = \"abcde\";\nstr_erase(s, 1, 2); // ade"
1696
+ },
1697
+ {
1698
+ "id": "str_replace_char",
1699
+ "title": "替换字符",
1700
+ "description": "原地将所有 old_char 替换为 new_char,返回替换次数。",
1701
+ "keywords": [],
1702
+ "related": [],
1703
+ "advancedSignatures": [],
1704
+ "signatures": [
1705
+ "int str_replace_char(char *s, char old_char, char new_char);"
1706
+ ],
1707
+ "example": "char s[] = \"banana\";\nint n = str_replace_char(s, 'a', 'o'); // 3"
1708
+ },
1709
+ {
1710
+ "id": "str_remove_char",
1711
+ "title": "删除指定字符",
1712
+ "description": "原地删除所有 key 字符,返回删除次数。",
1713
+ "keywords": [],
1714
+ "related": [],
1715
+ "advancedSignatures": [],
1716
+ "signatures": [
1717
+ "int str_remove_char(char *s, char key);"
1718
+ ],
1719
+ "example": "char s[] = \"banana\";\nint n = str_remove_char(s, 'a'); // bnn"
1720
+ },
1721
+ {
1722
+ "id": "str_replace_all",
1723
+ "title": "替换子串",
1724
+ "description": "原地替换所有非重叠匹配,返回替换次数。needle 非空;needle 和 replacement 不可指向目标缓冲区,目标容量须足够。",
1725
+ "keywords": [],
1726
+ "related": [],
1727
+ "advancedSignatures": [
1728
+ "int str_replace_all_into(char *s, const char *needle,\n const char *replacement,\n size_t capacity);"
1729
+ ],
1730
+ "signatures": [
1731
+ "str_replace_all(array, needle, replacement)",
1732
+ "int str_replace_all_into(char *s, const char *needle,\n const char *replacement,\n size_t capacity);"
1733
+ ],
1734
+ "example": "char s[30] = \"a--b--c\";\nint n = str_replace_all(s, \"--\", \":\"); // a:b:c"
1735
+ },
1736
+ {
1737
+ "id": "str_sort_chars",
1738
+ "title": "字符排序",
1739
+ "description": "原地按无符号字节值升序排列。",
1740
+ "keywords": [],
1741
+ "related": [],
1742
+ "advancedSignatures": [],
1743
+ "signatures": [
1744
+ "void str_sort_chars(char *s);"
1745
+ ],
1746
+ "example": "char s[] = \"cab\";\nstr_sort_chars(s); // abc"
1747
+ },
1748
+ {
1749
+ "id": "str_unique_chars",
1750
+ "title": "字符去重",
1751
+ "description": "原地去除重复字符,保留首次出现顺序,返回新长度。",
1752
+ "keywords": [],
1753
+ "related": [],
1754
+ "advancedSignatures": [],
1755
+ "signatures": [
1756
+ "int str_unique_chars(char *s);"
1757
+ ],
1758
+ "example": "char s[] = \"banana\";\nint n = str_unique_chars(s); // ban"
1759
+ },
1760
+ {
1761
+ "id": "str_split",
1762
+ "title": "按分隔符拆分",
1763
+ "description": "按非空字面分隔符拆分,保留空字段,返回字段数。words 为二维 char 数组,行数和每行容量须足够,不能与输入重叠。",
1764
+ "keywords": [],
1765
+ "related": [
1766
+ "str_split_whitespace",
1767
+ "str_join"
1768
+ ],
1769
+ "advancedSignatures": [
1770
+ "int str_split_into(const char *text, const char *delimiter,\n char *out_rows, size_t rows, size_t width);"
1771
+ ],
1772
+ "signatures": [
1773
+ "str_split(text, delimiter, rows)",
1774
+ "int str_split_into(const char *text, const char *delimiter,\n char *out_rows, size_t rows, size_t width);"
1775
+ ],
1776
+ "example": "char words[5][20];\nint n = str_split(\"a,,b,\", \",\", words); // 4"
1777
+ },
1778
+ {
1779
+ "id": "str_split_whitespace",
1780
+ "title": "按空白拆分",
1781
+ "description": "按连续空白拆分,忽略空字段,返回字段数。全空白输入返回 0。words 为足够大的二维 char 数组。",
1782
+ "keywords": [],
1783
+ "related": [
1784
+ "str_split",
1785
+ "str_join"
1786
+ ],
1787
+ "advancedSignatures": [
1788
+ "int str_split_whitespace_into(const char *text,\n char *out_rows,\n size_t rows, size_t width);"
1789
+ ],
1790
+ "signatures": [
1791
+ "str_split_whitespace(text, rows)",
1792
+ "int str_split_whitespace_into(const char *text,\n char *out_rows,\n size_t rows, size_t width);"
1793
+ ],
1794
+ "example": "char words[5][20];\nint n = str_split_whitespace(\" a b \", words); // 2"
1795
+ },
1796
+ {
1797
+ "id": "str_join",
1798
+ "title": "拼接字符串",
1799
+ "description": "拼接二维字符数组的前 n 行,分隔符只放在字段之间。输出到独立且足够大的 char 数组。n 为 0 时输出空串。",
1800
+ "keywords": [],
1801
+ "related": [
1802
+ "str_split",
1803
+ "str_split_whitespace"
1804
+ ],
1805
+ "advancedSignatures": [
1806
+ "void str_join_into(const char *rows, int n,\n size_t row_capacity, size_t width,\n const char *delimiter,\n char *output, size_t capacity);"
1807
+ ],
1808
+ "signatures": [
1809
+ "str_join(rows, n, delimiter, output)",
1810
+ "void str_join_into(const char *rows, int n,\n size_t row_capacity, size_t width,\n const char *delimiter,\n char *output, size_t capacity);"
1811
+ ],
1812
+ "example": "char words[3][10] = {\"a\", \"b\", \"c\"};\nchar out[30];\nstr_join(words, 3, \"-\", out); // a-b-c"
1813
+ }
1814
+ ]
1815
+ },
1816
+ {
1817
+ "title": "数学计算",
1818
+ "entries": [
1819
+ {
1820
+ "id": "gcd_lcm",
1821
+ "title": "最大公约数与最小公倍数",
1822
+ "description": "返回非负的 unsigned long long 结果。输入可以为负数。",
1823
+ "keywords": [],
1824
+ "related": [],
1825
+ "advancedSignatures": [],
1826
+ "signatures": [
1827
+ "unsigned long long gcd(long long a, long long b);",
1828
+ "unsigned long long lcm(long long a, long long b);"
1829
+ ],
1830
+ "example": "unsigned long long g = gcd(12, 18); // 6\nunsigned long long l = lcm(12, 18); // 36"
1831
+ },
1832
+ {
1833
+ "id": "integer_power",
1834
+ "title": "整数幂与模幂",
1835
+ "description": "指数为非负整数;mod_pow 的模数为正,适合大指数取模。int_pow 的结果必须在 long long 范围内。",
1836
+ "keywords": [],
1837
+ "related": [],
1838
+ "advancedSignatures": [],
1839
+ "signatures": [
1840
+ "long long int_pow(long long base, unsigned int exponent);",
1841
+ "long long mod_pow(long long base, unsigned long long exponent,\n long long modulus);"
1842
+ ],
1843
+ "example": "long long x = int_pow(2, 10); // 1024\nlong long y = mod_pow(2, 10, 7); // 2"
1844
+ },
1845
+ {
1846
+ "id": "factorial_basic",
1847
+ "title": "阶乘",
1848
+ "description": "计算 n!,n 范围 0..20,返回 long long。更大的阶乘使用 bigint_factorial。",
1849
+ "keywords": [],
1850
+ "related": [
1851
+ "bigint_factorial"
1852
+ ],
1853
+ "advancedSignatures": [],
1854
+ "signatures": [
1855
+ "long long factorial_basic(int n);"
1856
+ ],
1857
+ "example": "long long f = factorial_basic(5); // 120"
1858
+ },
1859
+ {
1860
+ "id": "prime_test",
1861
+ "title": "质数判断",
1862
+ "description": "判断单个整数是否为质数,小于 2 返回 false。多次查询可使用筛法。",
1863
+ "keywords": [],
1864
+ "related": [
1865
+ "prime_sieve"
1866
+ ],
1867
+ "advancedSignatures": [],
1868
+ "signatures": [
1869
+ "bool is_prime(long long n);"
1870
+ ],
1871
+ "example": "bool p = is_prime(97);"
1872
+ },
1873
+ {
1874
+ "id": "prime_sieve",
1875
+ "title": "质数筛法",
1876
+ "description": "标记 0..limit 是否为质数,flags 为至少 limit+1 项 unsigned char 数组。",
1877
+ "keywords": [],
1878
+ "related": [
1879
+ "prime_test"
1880
+ ],
1881
+ "advancedSignatures": [
1882
+ "void sieve_primes_into(unsigned char *flags, int limit,\n size_t capacity);"
1883
+ ],
1884
+ "signatures": [
1885
+ "sieve_primes(array, limit)",
1886
+ "void sieve_primes_into(unsigned char *flags, int limit,\n size_t capacity);"
1887
+ ],
1888
+ "example": "unsigned char flags[101];\nsieve_primes(flags, 100);\nif (flags[97]) print_text(\"prime\", \"\\n\");"
1889
+ },
1890
+ {
1891
+ "id": "base_conversion",
1892
+ "title": "进制转换",
1893
+ "description": "base 为 2..36。base_to_int 将字符串解析为 long long;int_to_base 将整数写成指定进制的字符串,目标容量包含结束符。",
1894
+ "keywords": [],
1895
+ "related": [],
1896
+ "advancedSignatures": [
1897
+ "void int_to_base_into(long long value, int base,\n char *out, size_t capacity);"
1898
+ ],
1899
+ "signatures": [
1900
+ "long long base_to_int(const char *s, int base);",
1901
+ "int_to_base(value, base, array)",
1902
+ "void int_to_base_into(long long value, int base,\n char *out, size_t capacity);"
1903
+ ],
1904
+ "example": "long long n = base_to_int(\"1010\", 2); // 10\nchar out[70];\nint_to_base(n, 16, out); // A"
1905
+ },
1906
+ {
1907
+ "id": "digit_stats",
1908
+ "title": "数位统计与取位",
1909
+ "description": "按指定进制统计数位数、数位和,或取指定数位。pos 从最低位开始编号 0。",
1910
+ "keywords": [],
1911
+ "related": [],
1912
+ "advancedSignatures": [],
1913
+ "signatures": [
1914
+ "int int_digit_count(long long n, int base);",
1915
+ "int int_digit_sum(long long n, int base);",
1916
+ "int int_digit_at(long long n, int base, int position);"
1917
+ ],
1918
+ "example": "int n = int_digit_count(123, 10); // 3\nint s = int_digit_sum(123, 10); // 6\nint d = int_digit_at(123, 10, 0); // 3"
1919
+ },
1920
+ {
1921
+ "id": "digit_array",
1922
+ "title": "整数与数位数组转换",
1923
+ "description": "int_to_digits 按最高位到最低位写入数位并返回个数;digits_to_int 按同一顺序合并,base 为 2..36。",
1924
+ "keywords": [],
1925
+ "related": [],
1926
+ "advancedSignatures": [
1927
+ "int int_to_digits_into(long long value,int base,\n int *out,size_t capacity);"
1928
+ ],
1929
+ "signatures": [
1930
+ "int_to_digits(value,base,array)",
1931
+ "long long digits_to_int(const int *digits,int n,int base);",
1932
+ "int int_to_digits_into(long long value,int base,\n int *out,size_t capacity);"
1933
+ ],
1934
+ "example": "int a[64];\nint n = int_to_digits(123, 10, a);\nlong long x = digits_to_int(a, n, 10); // 123"
1935
+ },
1936
+ {
1937
+ "id": "int_reverse_digits",
1938
+ "title": "反转十进制数位",
1939
+ "description": "反转十进制数位,返回整数,前导零自然消失。",
1940
+ "keywords": [],
1941
+ "related": [],
1942
+ "advancedSignatures": [],
1943
+ "signatures": [
1944
+ "long long int_reverse_digits(long long n);"
1945
+ ],
1946
+ "example": "long long n = int_reverse_digits(120); // 21"
1947
+ },
1948
+ {
1949
+ "id": "bit_edit",
1950
+ "title": "读取与修改二进制位",
1951
+ "description": "对 unsigned long long 操作,最低位为 0,位编号 0..63。修改接口返回新值,不修改传入变量。",
1952
+ "keywords": [],
1953
+ "related": [],
1954
+ "advancedSignatures": [],
1955
+ "signatures": [
1956
+ "int bit_get(unsigned long long x, int bit);",
1957
+ "unsigned long long bit_set(unsigned long long x, int bit);",
1958
+ "unsigned long long bit_clear(unsigned long long x, int bit);",
1959
+ "unsigned long long bit_toggle(unsigned long long x, int bit);"
1960
+ ],
1961
+ "example": "unsigned long long x = 4;\nint b = bit_get(x, 2); // 1\nx = bit_set(x, 0); // 5\nx = bit_clear(x, 2); // 1\nx = bit_toggle(x, 0); // 0"
1962
+ },
1963
+ {
1964
+ "id": "bit_stats",
1965
+ "title": "置位数与位置",
1966
+ "description": "统计为 1 的位数、判断二的幂,或返回最低/最高置位的编号。",
1967
+ "keywords": [],
1968
+ "related": [],
1969
+ "advancedSignatures": [],
1970
+ "signatures": [
1971
+ "int bit_count(unsigned long long x);",
1972
+ "bool is_power_of_two(unsigned long long x);",
1973
+ "int bit_lowest_set_index(unsigned long long x);",
1974
+ "int bit_highest_set_index(unsigned long long x);"
1975
+ ],
1976
+ "example": "int n = bit_count(10); // 2\nint lo = bit_lowest_set_index(10); // 1\nint hi = bit_highest_set_index(10); // 3\nbool p = is_power_of_two(8);"
1977
+ },
1978
+ {
1979
+ "id": "bit_rotate_left",
1980
+ "title": "循环左移",
1981
+ "description": "在 64 位无符号整数内循环左移,移出的位回到最低端。",
1982
+ "keywords": [],
1983
+ "related": [],
1984
+ "advancedSignatures": [],
1985
+ "signatures": [
1986
+ "unsigned long long bit_rotate_left(unsigned long long x, int count);"
1987
+ ],
1988
+ "example": "unsigned long long x = bit_rotate_left(1, 3); // 8"
1989
+ },
1990
+ {
1991
+ "id": "nearly_equal",
1992
+ "title": "浮点数比较",
1993
+ "description": "用绝对误差和相对误差容限判断两个数是否近似相等;容限为非负数。",
1994
+ "keywords": [],
1995
+ "related": [],
1996
+ "advancedSignatures": [],
1997
+ "signatures": [
1998
+ "bool nearly_equal(double a, double b,\n double absolute_tolerance,\n double relative_tolerance);"
1999
+ ],
2000
+ "example": "bool same = nearly_equal(0.1 + 0.2, 0.3, 1e-9, 1e-9);"
2001
+ },
2002
+ {
2003
+ "id": "round_digits",
2004
+ "title": "四舍五入",
2005
+ "description": "将数舍入到指定小数位数,返回 double。输出固定小数位仍需 printf 或 print_double。",
2006
+ "keywords": [],
2007
+ "related": [],
2008
+ "advancedSignatures": [],
2009
+ "signatures": [
2010
+ "double round_digits(double value, int digits);"
2011
+ ],
2012
+ "example": "double x = round_digits(3.14159, 2); // 3.14"
2013
+ },
2014
+ {
2015
+ "id": "bisect_root",
2016
+ "title": "二分求根",
2017
+ "description": "在连续函数的异号区间 [left,right] 内二分求根,端点为根也可。tolerance 为正的误差容限,iterations 为最大迭代次数。",
2018
+ "keywords": [],
2019
+ "related": [],
2020
+ "advancedSignatures": [],
2021
+ "signatures": [
2022
+ "double bisect_root(double (*f)(double), double left,\n double right, double tolerance, int iterations);"
2023
+ ],
2024
+ "example": "static double f(double x) { return x*x - 2; }\nint main(void) {\n double x = bisect_root(f, 1, 2, 1e-8, 100);\n print_double(x, 6, \"\\n\");\n return 0;\n}"
2025
+ },
2026
+ {
2027
+ "id": "complex_create",
2028
+ "title": "构造复数",
2029
+ "description": "Complex 是包含实部 re 和虚部 im 的值类型。complex_new(real, imaginary) 构造复数。",
2030
+ "keywords": [],
2031
+ "related": [
2032
+ "complex_arithmetic",
2033
+ "complex_output"
2034
+ ],
2035
+ "advancedSignatures": [],
2036
+ "signatures": [
2037
+ "typedef struct {\n double re, im;\n} Complex;",
2038
+ "Complex complex_new(double real, double imaginary);"
2039
+ ],
2040
+ "example": "Complex z = complex_new(3, 4);"
2041
+ },
2042
+ {
2043
+ "id": "complex_arithmetic",
2044
+ "title": "复数四则运算",
2045
+ "description": "接收两个 Complex 值,返回运算结果,不修改原值。除数不能为零。",
2046
+ "keywords": [],
2047
+ "related": [],
2048
+ "advancedSignatures": [],
2049
+ "signatures": [
2050
+ "Complex complex_add(Complex a, Complex b);",
2051
+ "Complex complex_sub(Complex a, Complex b);",
2052
+ "Complex complex_mul(Complex a, Complex b);",
2053
+ "Complex complex_div(Complex a, Complex b);"
2054
+ ],
2055
+ "example": "Complex a = complex_new(1, 2), b = complex_new(3, 4);\nComplex c = complex_add(a, b);\nComplex d = complex_mul(a, b);"
2056
+ },
2057
+ {
2058
+ "id": "complex_output",
2059
+ "title": "复数模长与输出",
2060
+ "description": "complex_abs 返回模;complex_print 指定小数位数 digits 和结束字符串 end。",
2061
+ "keywords": [],
2062
+ "related": [],
2063
+ "advancedSignatures": [],
2064
+ "signatures": [
2065
+ "double complex_abs(Complex z);",
2066
+ "void complex_print(Complex z, int digits, const char *end);"
2067
+ ],
2068
+ "example": "Complex z = complex_new(3, 4);\ndouble m = complex_abs(z); // 5\ncomplex_print(z, 2, \"\\n\");"
2069
+ },
2070
+ {
2071
+ "id": "poly_eval_lls",
2072
+ "title": "多项式求值",
2073
+ "description": "coefficients 按低次到高次排列,count 是系数个数,coefficients[0] 为常数项。返回 long long。",
2074
+ "keywords": [],
2075
+ "related": [],
2076
+ "advancedSignatures": [],
2077
+ "signatures": [
2078
+ "long long poly_eval_lls(const long long *coefficients,\n int count, long long x);"
2079
+ ],
2080
+ "example": "long long coef[] = {1, 2, 3};\nlong long y = poly_eval_lls(coef, 3, 2); // 17"
2081
+ },
2082
+ {
2083
+ "id": "bigint_create",
2084
+ "title": "大整数构造与初始化",
2085
+ "description": "BigInt 是固定容量的有符号十进制整数,默认最多 2048 位。先声明变量,再通过 bigint_zero、bigint_from_str 或 bigint_from_ll 初始化;不需要 free。",
2086
+ "keywords": [],
2087
+ "related": [
2088
+ "bigint_io",
2089
+ "bigint_arithmetic"
2090
+ ],
2091
+ "advancedSignatures": [],
2092
+ "signatures": [
2093
+ "typedef struct {\n int sign; /* -1, 0, +1; 0 is represented by sign=0,len=1,d[0]=0 */\n int len;\n unsigned char d[EXAM_BIGINT_CAP]; /* least significant digit first */\n} BigInt;",
2094
+ "void bigint_zero(BigInt *out);",
2095
+ "void bigint_from_str(BigInt *out, const char *text);",
2096
+ "void bigint_from_ll(BigInt *out, long long value);"
2097
+ ],
2098
+ "example": "BigInt a, b;\nbigint_from_str(&a, \"12345678901234567890\");\nbigint_from_ll(&b, -15);"
2099
+ },
2100
+ {
2101
+ "id": "bigint_io",
2102
+ "title": "大整数输入输出",
2103
+ "description": "传入 BigInt 地址。try_read_bigint 在正常 EOF 返回 false;bigint_print 追加 end;bigint_to_str 写入足够大的字符数组(含符号和结束符)。",
2104
+ "keywords": [],
2105
+ "related": [
2106
+ "bigint_create"
2107
+ ],
2108
+ "advancedSignatures": [
2109
+ "void bigint_to_str_into(const BigInt *a, char *out,\n size_t capacity);"
2110
+ ],
2111
+ "signatures": [
2112
+ "void read_bigint(BigInt *out);",
2113
+ "bool try_read_bigint(BigInt *out);",
2114
+ "void bigint_print(const BigInt *a, const char *end);",
2115
+ "bigint_to_str(a, array)",
2116
+ "void bigint_to_str_into(const BigInt *a, char *out,\n size_t capacity);"
2117
+ ],
2118
+ "example": "BigInt a;\nread_bigint(&a);\nbigint_print(&a, \"\\n\");"
2119
+ },
2120
+ {
2121
+ "id": "bigint_arithmetic",
2122
+ "title": "大整数加减法",
2123
+ "description": "结果写入第一个参数,允许结果与操作数别名。结果超出容量时报告错误。",
2124
+ "keywords": [],
2125
+ "related": [
2126
+ "bigint_mul",
2127
+ "bigint_div"
2128
+ ],
2129
+ "advancedSignatures": [],
2130
+ "signatures": [
2131
+ "void bigint_add(BigInt *out, const BigInt *a,\n const BigInt *b);",
2132
+ "void bigint_sub(BigInt *out, const BigInt *a,\n const BigInt *b);"
2133
+ ],
2134
+ "example": "BigInt a, b, c;\nbigint_from_str(&a, \"12345678901234567890\");\nbigint_from_ll(&b, -15);\nbigint_add(&c, &a, &b);\nbigint_print(&c, \"\\n\");"
2135
+ },
2136
+ {
2137
+ "id": "bigint_mul",
2138
+ "title": "大整数乘法",
2139
+ "description": "将乘积写入第一个参数。bigint_mul_small 的第二个操作数是 int;结果可与输入别名。",
2140
+ "keywords": [],
2141
+ "related": [],
2142
+ "advancedSignatures": [],
2143
+ "signatures": [
2144
+ "void bigint_mul(BigInt *out, const BigInt *a,\n const BigInt *b);",
2145
+ "void bigint_mul_small(BigInt *out, const BigInt *a, int factor);"
2146
+ ],
2147
+ "example": "BigInt a, b, c;\nbigint_from_ll(&a, 123);\nbigint_from_ll(&b, 456);\nbigint_mul(&c, &a, &b);\nbigint_mul_small(&c, &c, 2);"
2148
+ },
2149
+ {
2150
+ "id": "bigint_div",
2151
+ "title": "大整数除法",
2152
+ "description": "除数非零。商向零截断,余数与被除数同号或为零。divmod 的商和余数输出必须是不同变量;div_small 的除数和余数为 int。",
2153
+ "keywords": [],
2154
+ "related": [],
2155
+ "advancedSignatures": [],
2156
+ "signatures": [
2157
+ "void bigint_divmod(BigInt *quotient, BigInt *remainder,\n const BigInt *a, const BigInt *b);",
2158
+ "void bigint_div_small(BigInt *quotient, int *remainder,\n const BigInt *a, int divisor);"
2159
+ ],
2160
+ "example": "BigInt a, b, q, r;\nbigint_from_ll(&a, -17);\nbigint_from_ll(&b, 5);\nbigint_divmod(&q, &r, &a, &b); // -3, -2"
2161
+ },
2162
+ {
2163
+ "id": "bigint_compare",
2164
+ "title": "大整数比较",
2165
+ "description": "比较两个大整数,返回 -1、0 或 1。",
2166
+ "keywords": [],
2167
+ "related": [],
2168
+ "advancedSignatures": [],
2169
+ "signatures": [
2170
+ "int bigint_compare(const BigInt *a, const BigInt *b);"
2171
+ ],
2172
+ "example": "BigInt a, b;\nbigint_from_ll(&a, 5);\nbigint_from_ll(&b, 7);\nint cmp = bigint_compare(&a, &b); // -1"
2173
+ },
2174
+ {
2175
+ "id": "bigint_factorial",
2176
+ "title": "大整数阶乘",
2177
+ "description": "计算非负整数 n 的阶乘,结果写入 BigInt。结果不得超过容量。",
2178
+ "keywords": [],
2179
+ "related": [
2180
+ "factorial_basic"
2181
+ ],
2182
+ "advancedSignatures": [],
2183
+ "signatures": [
2184
+ "void bigint_factorial(BigInt *out, int n);"
2185
+ ],
2186
+ "example": "BigInt f;\nbigint_factorial(&f, 100);\nbigint_print(&f, \"\\n\");"
2187
+ }
2188
+ ]
2189
+ },
2190
+ {
2191
+ "title": "其他算法与工具",
2192
+ "entries": [
2193
+ {
2194
+ "id": "combinations",
2195
+ "title": "枚举组合",
2196
+ "description": "从 0..n-1 中无序选 r 项。初始化迭代器,每次 next 返回 true 时读取 indices[0..r-1]。默认 n <= 64;r=0 枚举一次空组合。",
2197
+ "keywords": [],
2198
+ "related": [
2199
+ "permutations"
2200
+ ],
2201
+ "advancedSignatures": [],
2202
+ "signatures": [
2203
+ "typedef struct {\n int n, r, started, finished;\n int indices[EXAM_ENUM_CAP];\n} Combination;",
2204
+ "Combination combination_new(int n, int r);",
2205
+ "bool combination_next(Combination *it);"
2206
+ ],
2207
+ "example": "Combination it = combination_new(5, 3);\nwhile (combination_next(&it)) {\n print_ints(it.indices, it.r, \" \", \"\\n\");\n}"
2208
+ },
2209
+ {
2210
+ "id": "permutations",
2211
+ "title": "枚举排列",
2212
+ "description": "从 0..n-1 中有序选 r 项。每次 next 返回 true 时读取 indices[0..r-1]。默认 n <= 64;r=0 枚举一次空排列。",
2213
+ "keywords": [],
2214
+ "related": [
2215
+ "combinations"
2216
+ ],
2217
+ "advancedSignatures": [],
2218
+ "signatures": [
2219
+ "typedef struct {\n int n, r, started, finished;\n int indices[EXAM_ENUM_CAP];\n int pool[EXAM_ENUM_CAP], cycles[EXAM_ENUM_CAP];\n} Permutation;",
2220
+ "Permutation permutation_new(int n, int r);",
2221
+ "bool permutation_next(Permutation *it);"
2222
+ ],
2223
+ "example": "Permutation it = permutation_new(5, 3);\nwhile (permutation_next(&it)) {\n print_ints(it.indices, it.r, \" \", \"\\n\");\n}"
2224
+ },
2225
+ {
2226
+ "id": "first_true_int",
2227
+ "title": "二分答案",
2228
+ "description": "在 [begin,end) 内寻找第一个满足 predicate 的整数,条件必须从 false 单调变为 true。全不满足返回 end。",
2229
+ "keywords": [],
2230
+ "related": [],
2231
+ "advancedSignatures": [],
2232
+ "signatures": [
2233
+ "int first_true_int(int begin, int end,\n bool (*predicate)(int));"
2234
+ ],
2235
+ "example": "static bool check(int x) { return x >= 10; }\nint main(void) {\n int ans = first_true_int(0, 100, check);\n print_int(ans, \"\\n\"); // 10\n return 0;\n}"
2236
+ },
2237
+ {
2238
+ "id": "date_io",
2239
+ "title": "读取与格式化日期",
2240
+ "description": "date_read 按年、月、日顺序读取三个空白分隔的整数。日期非法、输入不完整或不是整数时,诊断会指出出错的字段。\ndate_print 按格式输出并追加 end。%Y 补至四位,%m、%d 补至两位。字段可重排或省略;%- 去掉该字段的补零,%% 输出百分号,其余文字原样输出。格式记号非法时报告出错字节的位置。\n从旧版升级时,两参数调用改为 date_print(d, \"%Y-%m-%d\", end)。",
2241
+ "keywords": [
2242
+ "日期",
2243
+ "输入",
2244
+ "输出",
2245
+ "读",
2246
+ "格式",
2247
+ "补零"
2248
+ ],
2249
+ "related": [
2250
+ "date_create",
2251
+ "date_arithmetic"
2252
+ ],
2253
+ "advancedSignatures": [],
2254
+ "signatures": [
2255
+ "Date date_read(void);",
2256
+ "void date_print(Date x, const char *format, const char *end);"
2257
+ ],
2258
+ "example": "Date d = date_read(); // 输入 2024 2 9\ndate_print(d, \"%Y-%m-%d\", \"\\n\"); // 2024-02-09\ndate_print(d, \"%Y年%-m月%-d日\", \"\\n\"); // 2024年2月9日"
2259
+ },
2260
+ {
2261
+ "id": "date_create",
2262
+ "title": "日期构造与合法性",
2263
+ "description": "Date 使用公历 1..9999 年。date_new 构造日期;date_valid 检查合法性;date_day_of_year 返回一年中的第几天。",
2264
+ "keywords": [],
2265
+ "related": [],
2266
+ "advancedSignatures": [],
2267
+ "signatures": [
2268
+ "typedef struct { int year, month, day; } Date;",
2269
+ "Date date_new(int year, int month, int day);",
2270
+ "bool date_valid(Date x);",
2271
+ "bool date_is_leap(int year);",
2272
+ "int date_days_in_month(int year, int month);",
2273
+ "int date_day_of_year(Date x);"
2274
+ ],
2275
+ "example": "Date d = date_new(2024, 2, 29);\nbool ok = date_valid(d);\nint day = date_day_of_year(d); // 60"
2276
+ },
2277
+ {
2278
+ "id": "date_arithmetic",
2279
+ "title": "日期计算",
2280
+ "description": "date_add_days 返回偏移指定天数的日期;date_diff(a,b) 返回 b-a 的天数。compare 比较日期先后;serial 接口转换为连续日序号。",
2281
+ "keywords": [],
2282
+ "related": [],
2283
+ "advancedSignatures": [],
2284
+ "signatures": [
2285
+ "Date date_add_days(Date x, int delta);",
2286
+ "int date_diff(Date a, Date b);",
2287
+ "int date_compare(Date a, Date b);",
2288
+ "int date_to_serial(Date x);",
2289
+ "Date date_from_serial(int serial);"
2290
+ ],
2291
+ "example": "Date a = date_new(2024, 2, 28);\nDate b = date_add_days(a, 2);\nint n = date_diff(a, b); // 2\n// b 是 2024-03-01"
2292
+ },
2293
+ {
2294
+ "id": "time_io",
2295
+ "title": "读取与格式化时刻",
2296
+ "description": "time_read 按时、分、秒顺序读取三个空白分隔的整数。输入不完整或不是整数时,诊断会指出出错的字段。时刻越界时显示传入的时、分、秒。\ntime_print 按格式输出并追加 end。%H、%M、%S 默认各补至两位。字段可重排或省略;%- 去掉该字段的补零,%% 输出百分号,其余文字原样输出。格式记号非法时报告出错字节的位置。\n从旧版升级时,两参数调用改为 time_print(t, \"%H:%M:%S\", end)。",
2297
+ "keywords": [
2298
+ "时刻",
2299
+ "输入",
2300
+ "输出",
2301
+ "读",
2302
+ "格式",
2303
+ "补零"
2304
+ ],
2305
+ "related": [
2306
+ "time_create",
2307
+ "time_arithmetic"
2308
+ ],
2309
+ "advancedSignatures": [],
2310
+ "signatures": [
2311
+ "Time time_read(void);",
2312
+ "void time_print(Time t, const char *format, const char *end);"
2313
+ ],
2314
+ "example": "Time t = time_read(); // 输入 8 5 3\ntime_print(t, \"%H:%M:%S\", \"\\n\"); // 08:05:03\ntime_print(t, \"%-H:%M:%S\", \"\\n\"); // 8:05:03"
2315
+ },
2316
+ {
2317
+ "id": "time_create",
2318
+ "title": "时刻构造与合法性",
2319
+ "description": "Time 表示一天中的时刻。time_to_seconds 转为从午夜开始的秒数,time_from_seconds 转回 24 小时时刻。",
2320
+ "keywords": [],
2321
+ "related": [],
2322
+ "advancedSignatures": [],
2323
+ "signatures": [
2324
+ "typedef struct { int hour, minute, second; } Time;",
2325
+ "Time time_new(int h, int m, int s);",
2326
+ "bool time_valid(Time t);",
2327
+ "int time_to_seconds(Time t);",
2328
+ "Time time_from_seconds(int seconds);"
2329
+ ],
2330
+ "example": "Time t = time_new(12, 30, 0);\nbool ok = time_valid(t);\nint s = time_to_seconds(t);"
2331
+ },
2332
+ {
2333
+ "id": "time_arithmetic",
2334
+ "title": "时刻计算",
2335
+ "description": "加秒、下一秒和下一分钟按 24 小时循环。time_diff(a,b) 返回 b-a 的秒数,不自动跨日。",
2336
+ "keywords": [],
2337
+ "related": [],
2338
+ "advancedSignatures": [],
2339
+ "signatures": [
2340
+ "Time time_add_seconds(Time t, int delta);",
2341
+ "int time_diff(Time a, Time b);",
2342
+ "Time time_next_second(Time t);",
2343
+ "Time time_next_minute(Time t);"
2344
+ ],
2345
+ "example": "Time a = time_new(23, 59, 59);\nTime b = time_next_second(a);\n// b 是 00:00:00"
2346
+ }
2347
+ ]
2348
+ }
2349
+ ],
2350
+ "sections": [
2351
+ {
2352
+ "title": "输入与输出",
2353
+ "children": [
2354
+ {
2355
+ "title": "数字读写",
2356
+ "entries": [
2357
+ "read_number",
2358
+ "try_read_number",
2359
+ "print_number"
2360
+ ]
2361
+ },
2362
+ {
2363
+ "title": "字符读写",
2364
+ "entries": [
2365
+ "read_char",
2366
+ "try_read_char",
2367
+ "print_char"
2368
+ ]
2369
+ },
2370
+ {
2371
+ "title": "字符串读写",
2372
+ "entries": [
2373
+ "read_word",
2374
+ "read_line",
2375
+ "read_rest",
2376
+ "skip_line",
2377
+ "print_text"
2378
+ ]
2379
+ },
2380
+ {
2381
+ "title": "数组读写",
2382
+ "entries": [
2383
+ "read_arrays",
2384
+ "print_arrays"
2385
+ ]
2386
+ }
2387
+ ]
2388
+ },
2389
+ {
2390
+ "title": "数组与结构体",
2391
+ "children": [
2392
+ {
2393
+ "title": "构造与修改",
2394
+ "children": [
2395
+ {
2396
+ "title": "构造与复制",
2397
+ "entries": [
2398
+ "fill_arrays",
2399
+ "copy_arrays",
2400
+ "values_arrays",
2401
+ "range_arrays"
2402
+ ]
2403
+ },
2404
+ {
2405
+ "title": "原地修改",
2406
+ "entries": [
2407
+ "reverse_arrays",
2408
+ "swap_ints"
2409
+ ]
2410
+ }
2411
+ ]
2412
+ },
2413
+ {
2414
+ "title": "排序与查找",
2415
+ "children": [
2416
+ {
2417
+ "title": "排序与去重",
2418
+ "entries": [
2419
+ "sort_arrays",
2420
+ "bubble_sort_ints",
2421
+ "argsort_ints",
2422
+ "unique_arrays"
2423
+ ]
2424
+ },
2425
+ {
2426
+ "title": "查找",
2427
+ "entries": [
2428
+ "find_arrays",
2429
+ "linear_search_ints",
2430
+ "binary_search_arrays"
2431
+ ]
2432
+ }
2433
+ ]
2434
+ },
2435
+ {
2436
+ "title": "统计与连续段",
2437
+ "children": [
2438
+ {
2439
+ "title": "统计量",
2440
+ "entries": [
2441
+ "sum_mean_arrays",
2442
+ "extrema_arrays",
2443
+ "variance_arrays",
2444
+ "median_arrays"
2445
+ ]
2446
+ },
2447
+ {
2448
+ "title": "计数",
2449
+ "entries": [
2450
+ "count_arrays",
2451
+ "frequency_ints"
2452
+ ]
2453
+ },
2454
+ {
2455
+ "title": "连续段",
2456
+ "entries": [
2457
+ "longest_runs",
2458
+ "max_subarray_sum_ints",
2459
+ "max_forward_diff_ints"
2460
+ ]
2461
+ }
2462
+ ]
2463
+ },
2464
+ {
2465
+ "title": "区间计算",
2466
+ "entries": [
2467
+ "prefix_sum",
2468
+ "difference_array"
2469
+ ]
2470
+ },
2471
+ {
2472
+ "title": "结构体",
2473
+ "entries": [
2474
+ "record_type",
2475
+ "sort_records",
2476
+ "find_records_by"
2477
+ ]
2478
+ }
2479
+ ]
2480
+ },
2481
+ {
2482
+ "title": "字符串",
2483
+ "children": [
2484
+ {
2485
+ "title": "基本操作",
2486
+ "entries": [
2487
+ "str_reverse",
2488
+ "str_case",
2489
+ "str_trim",
2490
+ "str_is_palindrome"
2491
+ ]
2492
+ },
2493
+ {
2494
+ "title": "统计与查找",
2495
+ "entries": [
2496
+ "str_count_char",
2497
+ "str_count_substr",
2498
+ "str_longest_char_run"
2499
+ ]
2500
+ },
2501
+ {
2502
+ "title": "编辑与修改",
2503
+ "entries": [
2504
+ "str_insert",
2505
+ "str_erase",
2506
+ "str_replace_char",
2507
+ "str_remove_char",
2508
+ "str_replace_all"
2509
+ ]
2510
+ },
2511
+ {
2512
+ "title": "排序与去重",
2513
+ "entries": [
2514
+ "str_sort_chars",
2515
+ "str_unique_chars"
2516
+ ]
2517
+ },
2518
+ {
2519
+ "title": "拆分与拼接",
2520
+ "entries": [
2521
+ "str_split",
2522
+ "str_split_whitespace",
2523
+ "str_join"
2524
+ ]
2525
+ }
2526
+ ]
2527
+ },
2528
+ {
2529
+ "title": "数学计算",
2530
+ "children": [
2531
+ {
2532
+ "title": "整数与数论",
2533
+ "entries": [
2534
+ "gcd_lcm",
2535
+ "integer_power",
2536
+ "factorial_basic",
2537
+ "prime_test",
2538
+ "prime_sieve"
2539
+ ]
2540
+ },
2541
+ {
2542
+ "title": "进制与数位",
2543
+ "children": [
2544
+ {
2545
+ "title": "进制转换与数位",
2546
+ "entries": [
2547
+ "base_conversion",
2548
+ "digit_stats",
2549
+ "digit_array",
2550
+ "int_reverse_digits"
2551
+ ]
2552
+ },
2553
+ {
2554
+ "title": "位运算",
2555
+ "entries": [
2556
+ "bit_edit",
2557
+ "bit_stats",
2558
+ "bit_rotate_left"
2559
+ ]
2560
+ }
2561
+ ]
2562
+ },
2563
+ {
2564
+ "title": "实数计算",
2565
+ "entries": [
2566
+ "nearly_equal",
2567
+ "round_digits",
2568
+ "bisect_root"
2569
+ ]
2570
+ },
2571
+ {
2572
+ "title": "复数与多项式",
2573
+ "entries": [
2574
+ "complex_create",
2575
+ "complex_arithmetic",
2576
+ "complex_output",
2577
+ "poly_eval_lls"
2578
+ ]
2579
+ },
2580
+ {
2581
+ "title": "大整数",
2582
+ "children": [
2583
+ {
2584
+ "title": "构造与读写",
2585
+ "entries": [
2586
+ "bigint_create",
2587
+ "bigint_io"
2588
+ ]
2589
+ },
2590
+ {
2591
+ "title": "运算",
2592
+ "entries": [
2593
+ "bigint_arithmetic",
2594
+ "bigint_mul",
2595
+ "bigint_div",
2596
+ "bigint_compare",
2597
+ "bigint_factorial"
2598
+ ]
2599
+ }
2600
+ ]
2601
+ }
2602
+ ]
2603
+ },
2604
+ {
2605
+ "title": "其他算法与工具",
2606
+ "children": [
2607
+ {
2608
+ "title": "排列与组合",
2609
+ "entries": [
2610
+ "combinations",
2611
+ "permutations"
2612
+ ]
2613
+ },
2614
+ {
2615
+ "title": "通用二分",
2616
+ "entries": [
2617
+ "first_true_int"
2618
+ ]
2619
+ },
2620
+ {
2621
+ "title": "日期与时间",
2622
+ "children": [
2623
+ {
2624
+ "title": "日期",
2625
+ "entries": [
2626
+ "date_io",
2627
+ "date_create",
2628
+ "date_arithmetic"
2629
+ ]
2630
+ },
2631
+ {
2632
+ "title": "时刻",
2633
+ "entries": [
2634
+ "time_io",
2635
+ "time_create",
2636
+ "time_arithmetic"
2637
+ ]
2638
+ }
2639
+ ]
2640
+ }
2641
+ ]
2642
+ }
2643
+ ]
2644
+ }