亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

c#英文單詞分類統(tǒng)計示例分享

 更新時間:2014年03月04日 09:42:34   投稿:zxhpj  
本文給出的題目是給出一段英文,對其分類統(tǒng)計出英文單詞的個數(shù)如:長度為4的單詞有2個,長度為3的有1個,下面是題目答案

復(fù)制代碼 代碼如下:

using System;
using System.Linq;
namespace ConsoleApplication1
{
    /// <summary>
    /// 給出一段英文,分類統(tǒng)計(如:長度為4的單詞有2個:time,well)
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            string source = "Do one thing at a time,and do well";//已知英文語句
            string[] stringArray = source.Split(new char[] { ' ', ',' });
            var result = stringArray.GroupBy(s => s.Length).Select(s => new {
                Lenght = s.Select(x => x).FirstOrDefault().Length,
                Count = s.Count(),
                StringItems = s.Select(x => x)
            });
 
            foreach (var s in result)
            {
                string strResult = string.Empty;
                foreach (var item in s.StringItems)
                {
                    strResult += string.IsNullOrEmpty(strResult) ? item : " , " + item;
                }
                Console.WriteLine(string.Format("長度為{0}的單詞有{1}個:{2}", s.Lenght, s.Count, strResult));
            }           
            Console.ReadKey();
        }
    }
}

相關(guān)文章

最新評論