# 超级难题，来挑战挑战看！50分哟！

www.myexceptions.net  网友分享于：2013-12-27  浏览：4次

for   (int   i   =   0;   i   <   a.Length;   i++)
sum   +=   i;

for   (int   i   =   0;   j   <   a.Length;   i++)
for   (int   j   =   0;   j   <   i;   j++)
sum   +=   （i   +   j);

for   (int   i   =   0;   j   <   a.Length;   i++)
for   (int   j   =   0;   j   <   i;   j++)
for   (int   k   =   0;   k   <   j;   k++)
sum   +=   (i   +   j   +   k);

static   int   fun(string   a)
{
int   sum   =   0;
//在此写代码
return   sum;
}

------解决方案--------------------
0> 1> 2> 3> 4....> a.Length-1,满足条件的只有一种情况，就是0+1+2+3+...+a.Length-1
------解决方案--------------------
Sub DoIt(ByRef Sum As Integer, ByVal StrCode As String, ByVal CurLength As Integer, ByVal TempSum As Integer, ByVal Cyc As Integer)
Dim II As Integer
For II = 0 To CurLength - 1
If Cyc = StrCode.Length Then
Sum = TempSum + II
Else
Cyc += 1
TempSum += II
DoIt(Sum, StrCode, II, TempSum, Cyc)
End If
Next
End Sub

Function GetSum(ByVal StrCode As String) As Integer
Dim Sum As Integer
DoIt(Sum, StrCode, StrCode.Length, 0, 1)
Return Sum
End Function

Private Sub MyButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButton1.Click
MsgBox(GetSum( "abcd "))
End Sub