【发布时间】:2020-10-08 07:47:31
【问题描述】:
伙计们!我需要实现功能 static bool CheckSectionsIntersect 检查部分是否相交(右→;左←;下↓; 向上↑)。以连续方向的形式给定 N 个连续的具有固定尺寸的垂直和水平部分的列表。我不得不认为我会有N个部分的路线。 如果我到了以前去过的地方,该函数应该返回 True 。 例如:
N = 6: { 上、左、下、下、右、上} - 返回 True。
⬇⬅
⬇⬆ <- Start
➡⬆
N = 4: {下、左、上、左} - 返回 False。
⬅⬇ <- Start
⬆⬅
我写的代码不完整,因为我需要一些关于函数应该如何的建议:
static void Main()
{
string userInput = Console.ReadLine();
int numberOfSections = Convert.ToInt32(userInput);
string[] sectionDirection = new string[numberOfSections];
for (int i = 0; i < numberOfSections; i++)
{
sectionDirections[i] = Console.ReadLine();
}
Console.WriteLine(CheckSectionsIntersect(sectionDirection, numberOfSections));
}
static bool CheckSectionsIntersect(string[] sectionDirection, int numberOfSections)
{
return true; // I need an implementation here
}
}
}
请问我对这个实现有什么建议吗? 非常感谢!
【问题讨论】:
-
对不起,我不明白你的问题。你能改写一下吗?谢谢!
标签: c# function intersection directions