arrays - 二维数组中的移动元素
问题描述
我可以将元素“kanin”从维度 0 移动到 1,但不能使用我的 else 语句返回。我的目标是检查这个“元素”是否在维度 0 中,它移动到维度 1,如果它在维度 1 中,它移动到维度 0。但只有 if 语句有效
public static string[,] Kanin(string[,] strand) {
for (int i = 0; i < strand.GetLength(0); i++)
{
if (i==0)
{
for (int x = 0; x < strand.GetLength(1); x++)
{
if (strand[i, x] == "kanin")
{
for (int y = 0; y < strand.GetLength(1); y++)
{
if (strand[1, y] == "")
{
strand[1, y] = strand[i, x];
strand[i, x] = "";
}
}
}
}
}
else
{
for (int x = 0; x < strand.GetLength(0); x++)
{
if (strand[i, x] == "kanin")
{
for (int y = 0; y < strand.GetLength(0); y++)
{
if (strand[0, y] == "")
{
strand[0, y] = strand[i, x];
strand[i, x] = "";
}
}
}
}
}
}
return (strand);
}
解决方案
推荐阅读
- c++ - 向量的 C++ 读取访问冲突
- php - 在 MySQL 中使用 SELECT DISTINCT 从数据中删除非字母字符
- c - 每当我在输出端打印时出现额外字符
- azure - Azure 部署槽复制自定义域
- java - 在页面对象模型框架中存储数据的最佳方式是什么
- c - 将确切的定义留给图书馆客户
- ionic-framework - 在 ionic 3 应用程序 (cordova-androidwear) 上使用 cordova 插件
- php - How to give name to array values in PHP
- python - 如何访问 JSON 响应的元素
- javascript - 在reactjs中渲染一个数组