日期:2014-05-18 浏览次数:21298 次
protected internal void T()
{
Dictionary<int, int> p2 = new Dictionary<int, int>();
Add(p2, 1);
Add(p2, 1);
Add(p2, 2);
Add(p2, 3);
Add(p2, 4);
Add(p2, 5);
Add(p2, 6);
Add(p2, 13);
Add(p2, 12);
Add(p2, 11);
Add(p2, 12);
Add(p2, 11);
Add(p2, 12);
Interaction.MsgBox("1出现3次了吗:" + Repeat3(p2, 1));
Interaction.MsgBox("12出现3次了吗:" + Repeat3(p2, 12));
}
protected internal bool Repeat3(Dictionary<int, int> dictionary, int number)
{
if (dictionary.ContainsKey(number)) {
return (dictionary[number] > 2);
} else {
return false;
}
}
protected internal void Add(Dictionary<int, int> dictionary, int number)
{
if (dictionary.ContainsKey(number)) {
dictionary[number] += 1;
} else {
dictionary[number] = 1;
}
}
------解决方案--------------------
var last6 = list.Skip(list.Count - 6).ToList();
if (last.Select((x, i) => new { x, i }).All(x => (x.i % 2 == 0 || x.x == 12) && (x.i %2 == 1 || x.x == 11)))
{
...
}
------解决方案--------------------
bool b=!p2.Where(p=>new int[]{11,12}.Contains(p)).GroupBy(p=>p).All(g=>g.Count()>=3);
------解决方案--------------------
bool b=!p2.Where(p=>new int[]{11,12}.Contains(p)).GroupBy(p=>p).All(g=>g.Count()>=3);
------解决方案--------------------
如果仅仅是判断,可以简单点,如下:
List<int> p2 = new List<int>(); // TODO: 初始化为适当的值
p2.Add(1);
p2.Add(2);
p2.Add(3);
p2.Add(4);
p2.Add(5);
p2.Add(6);
p2.Add(13);
p2.Add(12);
p2.Add(11);
p2.Add(12);
p2.Add(11);
p2.Add(12);
p2.Add(11);
p2.Add(12);
string str="";
foreach (int i in p2)
str += i.ToString();
if (Regex.IsMatch(str, @"(1112){3,}"))
MessageBox.Show("重复三次");
------解决方案--------------------
原来我理解错了啊
------解决方案--------------------
protected internal void S()
{
List<int> p2 = new List<int>();
p2.Add(1);
p2.Add(2);
p2.Add(3);
p2.Add(4);
p2.Add(5);
p2.Add(6);
p2.Add(13);
p2.Add(12);
p2.Add(11);
p2.Add(12);
p2.Add(11);
p2.Add(12);
p2.Add(11);
p2.Add(12);
Interaction.MsgBox("[,11,,12,]:" + Repeat3(p2, ",11,,12,"));
Interaction.MsgBox("[,11,,3,]:" + Repeat3(p2, ",11,,3,"));
}
protected internal bool Repeat3(List<int> p2, string numbers)
{
StringBui