四大文化赛道完整展开
03-execution/run-001/source-snapshot/main.py
main.py
站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。
文件类型.py
10-cases/s4-jh-01-pattern-restore/03-execution/run-001/source-snapshot/main.py
import sys
def solve(data: str) -> str:
tokens = data.split()
if not tokens:
return ""
k = int(tokens[0])
pattern = list(tokens[1])
counts = [[0] * 26 for _ in range(k)]
for index, ch in enumerate(pattern):
if ch != "?":
counts[index % k][ord(ch) - 65] += 1
fill = []
for group in range(k):
best_count = -1
best_char = "A"
for offset in range(26):
value = counts[group][offset]
char = chr(offset + 65)
if value > best_count:
best_count = value
best_char = char
fill.append(best_char)
replaced = 0
for index, ch in enumerate(pattern):
if ch == "?":
pattern[index] = fill[index % k]
replaced += 1
return "\n".join(
[
f"restored={''.join(pattern)}",
f"replaced={replaced}",
]
)
if __name__ == "__main__":
sys.stdout.write(solve(sys.stdin.read()).strip())
sys.stdout.write("\n")