用自身替换字符串
您的目标是通过将原始字符串中的每个字符替换为之前的字符串来替换字符串,从第一个字符开始并环绕。这里有一些例子来说明我的意思:
第一个例子:
Input: program
Output: apgopra
How:
Program -> mrogram (replace p by m in program)
-> mpogpam (replace r by p in mrogram)
-> mprgpam (replace o by r in mpogpam)
-> mpropam (replace g by o in mprgpam)
-> mpgopam (replace r by g in mpropam)
-> mpgoprm (replace a by r in mpgopam)
-> apgopra (replace m by a in mpgoprm)
第二个例子:
Input: robot
Output: orbro
How:
Robot -> tobot (replace r by t in robot)
-> trbrt (replace o by r in tobot)
-> trort (replace b by o in trbrt)
-> trbrt (replace o by b in trort)
-> orbro (replace t by o in trbrt)
第三个例子:
Input: x
Output: x
How:
x -> x (replace x by x in x)
第四个例子:
Input: xy
Output: xx
How:
xy -> yy (replace x by y in xy)
-> xx (replace y by x in yy)
旁注:
- 字符串
x
将仅包含小写字母数字字符和空格 - 这是代码高尔夫球,因此以字节为单位的最短代码胜出!
我的修改符合您的原始想法吗?
—
LegionMammal978
看起来不错,我希望人们能理解,他们每一轮基本上都通过替换每一轮字符来加密加密的字符串。这些示例清楚地表明了这一点,所以我认为它们会。
—
Thomas W