数字平衡指数.ahk

Plain text
复制到剪贴板
Open code in new window
EnlighterJS 3 Syntax Highlighter
; https://rosettacode.org/wiki/Equilibrium_index#AutoHotkey
Equilibrium_index(list, BaseIndex=0){
StringSplit, A, list, `,
Loop % A0 {
i := A_Index , Pre := Post := 0
loop, % A0
if (A_Index < i)
Pre += A%A_Index%
else if (A_Index > i)
Post += A%A_Index%
if (Pre = Post)
Res .= (Res?", ":"") i - (BaseIndex?0:1)
}
return Res
}
list = -7, 1, 5, 2, -4, 3, 0
MsgBox % Equilibrium_index(list)
; https://rosettacode.org/wiki/Equilibrium_index#AutoHotkey Equilibrium_index(list, BaseIndex=0){ StringSplit, A, list, `, Loop % A0 { i := A_Index , Pre := Post := 0 loop, % A0 if (A_Index < i) Pre += A%A_Index% else if (A_Index > i) Post += A%A_Index% if (Pre = Post) Res .= (Res?", ":"") i - (BaseIndex?0:1) } return Res } list = -7, 1, 5, 2, -4, 3, 0 MsgBox % Equilibrium_index(list)
; https://rosettacode.org/wiki/Equilibrium_index#AutoHotkey
Equilibrium_index(list, BaseIndex=0){
  StringSplit, A, list, `,
  Loop % A0 {
    i := A_Index	, Pre := Post := 0
    loop, % A0
      if (A_Index < i)
        Pre += A%A_Index%
      else if (A_Index > i)
        Post += A%A_Index%
    if (Pre = Post)
      Res .= (Res?", ":"") i - (BaseIndex?0:1)
  }
  return Res
}

list = -7, 1, 5, 2, -4, 3, 0
MsgBox % Equilibrium_index(list)

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。