欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#英文單詞分類(lèi)統(tǒng)計(jì)示例分享

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

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

using System;
using System.Linq;
namespace ConsoleApplication1
{
    /// <summary>
    /// 給出一段英文,分類(lèi)統(tǒng)計(jì)(如:長(zhǎng)度為4的單詞有2個(gè):time,well)
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            string source = "Do one thing at a time,and do well";//已知英文語(yǔ)句
            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("長(zhǎng)度為{0}的單詞有{1}個(gè):{2}", s.Lenght, s.Count, strResult));
            }           
            Console.ReadKey();
        }
    }
}

相關(guān)文章

最新評(píng)論