c# - 必须保存数组元素的位置
问题描述
我用了翻译器。对不起。
你好!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# - 进程 'C:\hostedtoolcache\windows\octo\7.4.1\x64\octo.cmd' > 失败,退出代码 4294967289 无法部署发布进程
- discord - Discord.py 让机器人等待回复
- java - java String Array : 从用户那里获取信息并显示数组中的数字
- html - 为什么 css repeat() 不使用自定义属性?
- python - 如何使用 Python 中的调用方方法将对象传递给类中的函数?
- node.js - 如何解决错误:在 nodejs 中读取 ECONNRESET
- python - Grouping values from list into buckets to keep sum of values at or below threshold
- flutter - Flutter 断言失败,但可以使用资产
- java - 我们如何将嵌套集合声明为一种类型(如 HashMap 中的 HashMap)?
- javascript - 限制 chrome 扩展中的谷歌地图 api 键