cswork / OA打开练习工作台

JPMorgan ChaseOA #16

Generate Table of Contents

估计简单可在线判题

考点(AI 标注)字符串模拟/实现

Lines that start strictly with "# " are chapters, lines that start with "## " are sections, and all other lines are ignored; the first valid heading is guaranteed to be a chapter. Chapters are numbered from 1, and section numbers restart from 1 in each new chapter. Only the fixed marker prefix is removed; titles are not trimmed. If there are no valid headings, the table of contents is empty.

输入格式

The input is a JSON array of strings; 1≤number of lines≤1000, and each line has 1..100 Unicode code points. The original does not restrict the character set; JSON escapes preserve NUL, newlines, and other control characters, and empty titles are allowed.

输出格式

Output a single-line canonical JSON array followed by a newline; an empty table of contents is []. Put one space after each comma; output non-ASCII characters directly; escape double quotes and backslashes; use \b/\t/\n/\f/\r for backspace/tab/newline/form feed/carriage return, use lowercase four-digit \u00xx for the rest of U+0000..U+001F, and do not escape slashes. This matches Python json.dumps(result, ensure_ascii=False); the checker is exact.

样例 1

输入:

["# Algorithms", "text", "## Sorting", "## Searching", "# Data Structures"]

输出:

["1. Algorithms", "1.1. Sorting", "1.2. Searching", "2. Data Structures"]

样例 2

输入:

["body", "#  A ", "## \t B ", "# "]

输出:

["1.  A ", "1.1. \t B ", "2. "]

样例 3

输入:

["ordinary text"]

输出:

[]

样例说明

The outputs of the three public examples are, in order: ["1. Algorithms", "1.1. Sorting", "1.2. Searching", "2. Data Structures"]; ["1. A ", "1.1. \t B ", "2. "]; []. These answers have been checked by independent enumeration or direct simulation.