CodinGame Manhattan

时间:2017-08-03 04:02:20

标签: c# arrays

我在半天的时间里遇到了IndexOutOfRangeException问题,无法找到问题所在。

中的问题
for (int k = 0; k < 27; k++)
        {
           for (int i = 0; i < H; i++)
           {

                Alphabet[i,0,k] = "0"; 
           }

        }

我使用Alphabet [i,0,k] =&#34; 0&#34;用于调试。实际上即使我使用Alphabet [0,0,0]也会进行预测,尽管我已经初步确定了该阵列。 H = 5.并且代码似乎第一次工作

using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

class Solution
{
    static void Main(string[] args)
    {
        int L = int.Parse(Console.ReadLine());
        int H = int.Parse(Console.ReadLine());
        string T = Console.ReadLine();
        Console.Error.WriteLine(T);
        Console.Error.WriteLine(T[0]);
        int stringLenght = T.Length;
        string [,] Row = new string [H,L*27];
        string [,,] Alphabet = new string [H,0,27];
        string [,] Word = new string [H,0];
        for (int i = 0; i < H; i++)
        {
            string initRow = Console.ReadLine();
            for (int j = 0; j < (L*27); j++)
            {
                Row[i,j] = Convert.ToString(initRow[j]);

            }

        }

        for (int k = 0; k < 27; k++)
        {
           for (int i = 0; i < H; i++)
           {

                 Console.Error.WriteLine("k=" + k);
                  Console.Error.WriteLine("i=" + i);
                Alphabet[i,0,k] = "0"; 
           }

        }


        for (int i =0; i < stringLenght; i++)
        {
          switch (T[i])
          {
              case 'E':
                   for (int j=0; j < H; j++)
                   {
                   Word[j,0] = Alphabet[j,0,3];
                   }
                   break;
              default: break;       
        }    

        }      



        for (int i=0; i<H; i++)
        {
        Console.WriteLine(Word[i,0]);
        }   
    }
}

        }


        for (int i =0; i < stringLenght; i++)
        {
          switch (T[i])
          {
              case 'E':
                   for (int j=0; j < H; j++)
                   {
                   Word[j,0] = Alphabet[j,0,3];
                   }
                   break;
              default: break;       
        }    

        }      




        for (int i=0; i<H; i++)
        {
        Console.WriteLine(Word[i,0]);
    }   }
}

1 个答案:

答案 0 :(得分:0)

数组的第二维长度为0:

String [,,] Alphabet = new string [H,0,27];

没有元素可供阅读。