日期:2014-05-17 浏览次数:20830 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<int> list = new List<int>() { 6, 1, 3, 0, 14, 5, 7, 9, 2, 1, 8, 3, 2, 4 };
List<List<int>> result = new List<List<int>>();
if (list.Count() < 2) return;
List<int> cur = list[0] % 2 == 1 ? new List<int>() { list[0] } : new List<int>();
list.Skip(1).Aggregate(list[0], (pre, current) =>
{
if (current == pre + 2 && pre % 2 == 1)
cur.Add(current);
if (current != pre + 2 && current % 2 == 1)
{
if (cur.Count > 1) result.Add(cur.ToList());
cur = new List<int>() { current };
}
return current;
});
foreach (List<int> item in result)
Console.WriteLine("{{ {0} }}", string.Join(", ", item));
}
}
}
List<int[]> resultsList = new List<int[]>