我正在埃菲尔为学校实验室编程,其中一项任务是在给定算法中找到错误。该算法返回第一个重复的字符。
该算法的工作原理如下:
word: STRING
first_repeated_character: CHARACTER
local
i: INTEGER
ch: CHARACTER
stop: BOOLEAN
do
from
i := 1
Result := '%U'
until
i > word.count or stop
loop
ch := word[i]
if ch = word[i + 1] then
Result := ch
stop := true
end
i := i + 1
end
end
我花了最后几个小时试图找到其中的错误,但它总是通过所有测试。
任何帮助将非常感激。谢谢。