我试图解决这个问题,即找出两个单词是否是彼此的字谜(如果我们重新排列一个字符串,它匹配第二个字符串)。
基于Remove single character from a string我建立了自己的功能:
public class AreAnagrams
{
public static bool AreStringsAnagrams(string FirstString, string SecondString)
{
if (FirstString == null || b == null)
return false;
if (FirstString.Length != SecondString.Length)
return false;
for (int i = 0; i < SecondString.Length; i++)
{
if (FirstString.IndexOf(SecondString[i]) == -1)
return false;
else
FirstString.Remove(FirstString.IndexOf(SecondString[i]), 1); // Here it does not modify FirstString, even if I put 2nd parameter as 1
}
if (FirstString.Length > 0)
return false;
return true;
}
public static void Main(string[] args)
{
Console.WriteLine(AreStringsAnagrams("neural", "unreal"));
}
}
在我的手表上,我看到FirstString
仍然是原样。问题是什么?拜托,谢谢
答案 0 :(得分:0)
将结果分配给 Cos(Theta) = Length(P - M) / Length(P - P0) = DM / L
D = Length(C - P) = L / Cos(Theta) = L * L / DM
and finally
C = P - L^2 * (P0 - M) / DM^2
Coeff = L_Squared / DM_Squared ///5
C.X = P.X - Coeff * (P.X - M.X) ///6
C.Y = P.Y - Coeff * (P.Y - M.Y) ///7
FirstString