将下列文件
1,1,0,0,0,0,0,0,
1,1,1,0,0,0,0,0,
0,1,1,1,0,0,0,0,
0,0,1,1,0,0,0,0,
0,1,1,1,0,0,0,0,
0,0,1,1,0,0,0,0,
0,0,1,1,0,0,0,0,
0,1,1,1,0,0,0,0,
中的每一个元素 以它周围 包括本身的九个元素的值相加作为该元素的新的值 
4,5,3,1,0,0,0,0,
5,7,6,3,1,0,0,0,
3,6,7,5,2,0,0,0,
2,5,8,6,3,0,0,0,
1,4,7,6,3,0,0,0,
1,3,7,6,3,0,0,0,
1,4,7,6,3,0,0,0,
1,3,5,3,1,0,0,0, 
在将每行中的最大的元素保留 其余值均改为 0
0,5,0,0,0,0,0,0,
0,7,0,0,0,0,0,0,
0,0,7,0,0,0,0,0,
0,0,8,0,0,0,0,0,
0,0,7,0,0,0,0,0,
0,0,7,0,0,0,0,0,
0,0,7,0,0,0,0,0,
0,0,5,0,0,0,0,0,
对每行所剩下的最大值的数据  (按北1,东北2,东3,东南4,南5,西南6,西7,西北0)相对与上一行的数据的位置另外得出一个一位数组 (比如第二行的最大数位于第一行的东南  ,则记第一个数为4 )
5,4,5,5,5,5,5,
将此一位数组中的奇数个数记为m=6偶数个数记为n=1  最后结果是计算出y=m+1+根号二*n的值

解决方案 »

  1.   

    其中
    1,1,0,0,0,0,0,0,
    1,1,1,0,0,0,0,0,
    0,1,1,1,0,0,0,0,
    0,0,1,1,0,0,0,0,
    0,1,1,1,0,0,0,0,
    0,0,1,1,0,0,0,0,
    0,0,1,1,0,0,0,0,
    0,1,1,1,0,0,0,0,
    这个要从一个TXT 文件中读出
      

  2.   

    哪个高手作出来了请发到[email protected]
    多谢了!
      

  3.   

    注意,有些中间过程的数据不必如题保存在数组中,代码中做了调整,以提高效能。Option ExplicitPrivate Sub Command1_Click()
    Dim arr() As Integer, line() As String, tmp As String
    Dim i As Integer, n As Integer
    Dim max() As Integer, maxtmp As Integer, sum As Integer
    Dim code() As Integer
    Dim y As Double'初始化
    n = 0
    Open "c:\my documents\test.txt" For Input As #1     '打开文件
    Do Until EOF(1)
    ReDim Preserve arr(7, n)
    ReDim Preserve max(n)Line Input #1, tmp                                  '读入一行
    Debug.Print tmp
    tmp = Replace(tmp, ",", ",")
    line = Split(tmp, ",")                              '拆分
    For i = 0 To 7
        arr(i, n) = Val(line(i))                        '存入数组
    Next i
    n = n + 1
    Loop'计算相邻格点
    For n = 0 To UBound(arr, 2)
        maxtmp = 0
        Debug.Print n & ": ";
        For i = 0 To 7
            sum = arr(i, n)
            If n > 0 Then
                If i > 0 Then sum = sum + arr(i - 1, n - 1) '加西北
                sum = sum + arr(i, n - 1)                   '加北
                If i < 7 Then sum = sum + arr(i + 1, n - 1) '加东北
            End If
            If i > 0 Then sum = sum + arr(i - 1, n)         '加西
            If i < 7 Then sum = sum + arr(i + 1, n)         '加东
            If n < UBound(arr, 2) Then
                If i > 0 Then sum = sum + arr(i - 1, n + 1) '加西南
                sum = sum + arr(i, n + 1)                   '加南
                If i < 7 Then sum = sum + arr(i + 1, n + 1) '加东南
            End If
            If sum > maxtmp Then
                maxtmp = sum
                max(n) = i                                  '保存最大值位置
            End If
            Debug.Print sum;
        Next i
        Debug.Print vbTab & "Max:" & maxtmp & " in colunm " & max(n)
    Next n'计算位置代码
    ReDim code(1 To UBound(arr, 2))
    i = 0
    For n = 1 To UBound(arr, 2)
        code(n) = 5
        If max(n) < max(n - 1) Then code(n) = 6
        If max(n) > max(n - 1) Then code(n) = 4
        Debug.Print code(n);
        
        If max(n) <> max(n - 1) Then i = i + 1              '记录偶数个数
    Next n
    Debug.Print'奇数个数记为m=6偶数个数记为n=1
    'y=m+1+根号二*n
    n = UBound(code) - i
    Debug.Print "Odds: " & n & "  Evens:" & i
    y = 1.414
    y = y * i
    y = y + n + 1Debug.Print yEnd Sub
      

  4.   

    调试的时候提示
    arr(i, n) = Val(line(i))                        '存入数组
    出错!
      

  5.   

    调试的时候
    arr(i, n) = Val(line(i))                        '存入数组
    出错!
    这是什么原因啊
    来个大侠来帮忙看看吧
      

  6.   

    可能 c:\my documents\test.txt 有问题
      

  7.   

    不是吧
    调试的时候看到已经能把TXT里的第一行数据读到程序里了!