日期:2014-05-20 浏览次数:21162 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var data = @"005, 014, 023, 032, 041
050, 104, 114, 123, 132
140, 141, 203, 213, 223
230, 231, 232, 239, 293
302, 312, 320, 321, 322
329, 392, 401, 410, 411
500, 923, 932, 999".Replace("\r\n", ", ").Split(',').Select(x => x.Trim());
var result1 = data.Where(x => x.Distinct().Count() == 2);
Console.WriteLine(string.Join(", ", result1));
var result2 = data.Distinct().OrderBy(x => x);
Console.WriteLine(string.Join(", ", result2));
}
}
}
------解决方案--------------------
int[] numbers = new int[]{005, 014, 023, 032, 041,
050, 104, 114, 123, 132,
140, 141, 203, 213, 223,
230, 231, 232, 239, 293,
302, 312, 320, 321, 322,
329, 392, 401,410, 411,
500, 923, 932,999};
var query = (from i in numbers
orderby i
select i).Distinct();
foreach (int i in query)
Console.WriteLine(i.ToString().PadLeft(3,'0'));
------解决方案--------------------
var data = @"005, 014, 023, 032, 041,
050, 104, 114, 123, 132,
140, 141, 203, 213, 223,
230, 231, 232, 239, 293,
302, 312, 320, 321, 322,
329, 392, 401, 410, 411,
500, 923, 932,999".Replace("\r\n", ", ").Split(',').Select(t => t.Trim());
var source = from temp in data where temp.Trim() != "" && temp.Distinct().Count() <= 2 select new { t = temp };