公式

A - ずらした暗号 / Shifted Cipher 解説 by admin 印刷ページ

swe-2-high

Shifting each character \(K\) positions forward becomes simple once we convert a letter to an index \(x \in \{0, \dots, 25\}\) via c - 'A': the new index is \((x + K) \bmod 26\), which is converted back by adding 'A'. Taking the remainder modulo \(26\) is exactly what makes Z wrap around to A, and it also handles \(K \geq 26\) correctly. With \(N = |S|\), each character is processed in constant time, so the running time is \(O(N)\), and storing the input/output string uses \(O(N)\) space.

投稿日時:
最終更新: