2
我把所有字母的字典映射到莫爾斯電碼Dictionary.ContainsValue()總是返回true
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("a", ".-");
data.Add("b", "-...");
data.Add("c", "-.-.");
data.Add("d", "-..");
data.Add("e", ".");
data.Add("f", "..-.");
data.Add("g", "--.");
data.Add("h", "....");
data.Add("i", "..");
data.Add("j", ".---");
data.Add("k", "-.-");
data.Add("l", ".-..");
data.Add("m", "--");
data.Add("n", "-.");
data.Add("o", "---"); and so on..
我想如果現有的摩爾斯電碼的子存在於字典來檢查的條件或不。
foreach (var item in arraylist)
{
int smallcount=0;
int startIndex = 0;
//check if this combination exists for morse code
for(int w=0;w<shortInput;w++)
{
int substringLength=Convert.ToInt32(item[w].ToString());
string sub = morsecode.Substring(startIndex, substringLength);
if (data.ContainsValue(sub)) ;
{
smallcount++;
}
startIndex = startIndex + substringLength;
}
if(smallcount==shortInput)
{ count++; }
}
這裏data.ContainsValue(sub)
即使值不存在於字典總是返回true。
任何人都可以告訴我,如果我失去了什麼。
多麼愚蠢的錯誤。萬分感謝 :-) – kakroo