Procedure DiscoverSomethingInteresting(Input : Array Of Integer; Out x, y, z : Integer);
Var
    i, j, k : Integer;
    w      : Integer;
Begin
    z := -MaxInt;
    For i := 1 To Length(Input) Do
    Begin
        For j := 0 To Length(Input) - i Do
        Begin
            w := 0;
            For k := 0 To i - 1 Do
            Begin
                w := w + Input[j+k];
            End;
            If w > z Then
            Begin
                z      := w;
                x      := j;
                y      := j+i-1;
            End;
        End;
    End;
End;
-------------------------
一道面试的题是用Delphi 写的。 我只学过 c# 和php 哪位学过Delphi 能帮我把代码转换成c# 的或者帮我说说 代码的意思。题目中说代码中有逻辑错误,哪位看出来了能不能指点一下!
先谢谢各位 了。

解决方案 »

  1.   

            public void DiscoverSomethingInteresting(int[] Input, out int x, out int y, out int z)
            {
                int i, j, k;
                int w;
                z = -MaxInt;
                for (i = 1; i < Length(Input) + 1; i++)
                {
                    for (j = 0; j < Length(Input) - i + 1; j++)
                    {
                        w = 0;
                        for (k = 0; k < i; k++)
                        {
                            w = w + Input[j + k];
                        }
                        if (w > z)
                        {
                            z = w;
                            x = j;
                            y = j + i + 1;
                        }
                    }
                }
            }仅供参考
      

  2.   

    在delphi中MaxInt是32位有符号整形的最大值(High(Integer))的编译器常量,对应着.net的 int.MaxValue 或 Int32.MaxValue;Length是数组长,在c#中直接取数组属性 Input.Length 即可。其它的应该翻译的没什么问题
    至于逻辑错误,谁也没工夫猜这个“有趣的发现”到底是啥
      

  3.   

    这个帖子里面不是已经回答过了么
    http://topic.csdn.net/u/20090203/15/ba6b485c-31d8-4846-8c0d-0696f50cb274.html