首页 > 解决方案 > 必须保存数组元素的位置

问题描述

我用了翻译器。对不起。

你好!C# 我是初学者。请帮助我,因为我很难写......每当数组的坐标发生变化时,我想将更改后的坐标保存在不同的数组中。我应该怎么办?请指教。你只需要指明方向。谢谢!

            string size = Console.ReadLine();
            int Consize = Convert.ToInt32(size);
            int[,] array = new int[Consize, Consize];
            for (int i = 0; i < Consize; i++)
            {
                string value = Console.ReadLine();
                string[] result = value.Split();

                for (int j = 0; j < result.Length; j++)
                {
                    int value2 = Convert.ToInt32(result[j]);
                    array[i, j] = value2;

这是一个存储输入数组的数组 A。

            int x = 0, y = 0;
            string movePath = "";
            int _max = 0;
            while (x != Consize && y != Consize)
            {
                int[,] _array = new int[x, y];
                int max = -101; 
                int[] temp = new int[4] { -101, -101, -101, -101 };

                if (x - 1 > 0)
                    temp[0] = array[x - 1, y];

                if (y - 1 > 0)
                    temp[1] = array[x, y - 1];

                if (x + 1 < Consize)
                    temp[2] = array[x + 1, y];

                if (y + 1 < Consize)
                    temp[3] = array[x, y + 1];

                int index = 0;
  for (int i = 0; i < temp.Length; i++)
                {
                    if (max < temp[i])
                    {
                        max = temp[i];
                        index = i;
                    }
                }
                switch (index)
                {
                    case 0:
                        movePath += "U";
                        _max += temp[0];
                        x--;
                        break;
                    case 1:
                        movePath += "L";
                        _max += temp[1];
                        y--;
                        break;
                    case 2:
                        movePath += "D";
                        _max += temp[2];
                        x++;
                        break;
                    case 3:
                        movePath += "R";
                        _max += temp[3];
                        y++;
                        break;
                    default:
                        break;
                }

比较数组的每个元素 他们继续讨论大因素。我想以不同的排列保存移动元素的坐标。

标签: c#arrays

解决方案


推荐阅读