最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言每日練習(xí)之統(tǒng)計(jì)文本單詞數(shù)及高頻詞

 更新時(shí)間:2022年05月18日 10:58:23   作者:德宏大魔王  
本文文大家準(zhǔn)備了個(gè)C語言練習(xí)題:統(tǒng)計(jì)單詞數(shù)并找出頻率最高的單詞,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C語言有一定幫助,感興趣的可以了解一下

作業(yè)1:統(tǒng)計(jì)出txt文本里面的單詞數(shù),并找出頻率出現(xiàn)最高的單詞是哪個(gè)?

運(yùn)行結(jié)果:

上代碼:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //文件打開
            //string file = System.IO.File.ReadAllLines(@"");
            int count = 0;
            string tmp = "";
            //初始化次數(shù)
            string words = "hihi hello,hihi,hello,hihi?";
            var new_i = words.Split(new char[] { ' ', ',', '.', '?' },StringSplitOptions.RemoveEmptyEntries);
            Console.Write("總的單詞數(shù)量:{0}\n", new_i.Length);
            for (int i = 0; i < new_i.Length; i++)
            {
                //查詢每個(gè)單詞出現(xiàn)的次數(shù)
                var query = from key in new_i where key.ToUpperInvariant() == new_i[i].ToUpperInvariant() select key;
                int key_count = query.Count();
                if (key_count > count) {

                    count = key_count;
                    tmp = new_i[i];
                }
               
            }

            Console.Write("頻率出現(xiàn)最高的單詞是:{0}\n", tmp);
            Console.Write("次數(shù)為:{0}\n", count);
            
            Console.ReadKey();
            
        }
    }
}

基礎(chǔ)代碼運(yùn)行成功!通過外部打開!

創(chuàng)建11.txt

通過外部打開:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //文件打開
            //string[] file_A = System.IO.File.ReadAllLines(@"C:\Users\Administrator\Desktop\11.txt");
            string file_A = System.IO.File.ReadAllText(@"C:\Users\Administrator\Desktop\11.txt");
            //Console.Write(file_A);
            int count = 0;
            string tmp = "";
            //初始化次數(shù)
            
            var new_i = file_A.Split(new char[] { ' ', ',', '.', '?' }, StringSplitOptions.RemoveEmptyEntries);
            Console.Write("總的單詞數(shù)量:{0}\n", new_i.Length);
            for (int i = 0; i < new_i.Length; i++)
            {
                //查詢每個(gè)單詞出現(xiàn)的次數(shù)
                var query = from key in new_i where key.ToUpperInvariant() == new_i[i].ToUpperInvariant() select key;
                int key_count = query.Count();
                if (key_count > count) {

                    count = key_count;
                    tmp = new_i[i];
                }
               
            }

            Console.Write("頻率出現(xiàn)最高的單詞是:{0}\n", tmp);
            Console.Write("次數(shù)為:{0}\n", count);
            
            Console.ReadKey();
            
        }
    }
}

運(yùn)行截圖:

到此這篇關(guān)于C語言每日練習(xí)之統(tǒng)計(jì)文本單詞數(shù)及高頻詞的文章就介紹到這了,更多相關(guān)C語言統(tǒng)計(jì)文本單詞數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 基于C++實(shí)現(xiàn)五子棋AI算法思想

    基于C++實(shí)現(xiàn)五子棋AI算法思想

    這篇文章主要為大家詳細(xì)介紹了基于C++實(shí)現(xiàn)五子棋AI算法思想,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • atoi和itoa函數(shù)的實(shí)現(xiàn)方法

    atoi和itoa函數(shù)的實(shí)現(xiàn)方法

    本文介紹了,atoi和itoa函數(shù)的實(shí)現(xiàn)方法,需要的朋友可以參考一下
    2013-03-03
  • vs2022?qt環(huán)境搭建調(diào)試的方法步驟

    vs2022?qt環(huán)境搭建調(diào)試的方法步驟

    最近net6和vs2022發(fā)布,本文就詳細(xì)的介紹一下vs2022?qt環(huán)境搭建調(diào)試的方法步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • 理解C++編程中的std::function函數(shù)封裝

    理解C++編程中的std::function函數(shù)封裝

    這篇文章主要介紹了理解C++編程中的std::function函數(shù)封裝,std::function是C++11標(biāo)準(zhǔn)中的新特性,需要的朋友可以參考下
    2016-04-04
  • 使用opencv實(shí)現(xiàn)車道線檢測(cè)實(shí)戰(zhàn)代碼

    使用opencv實(shí)現(xiàn)車道線檢測(cè)實(shí)戰(zhàn)代碼

    這篇文章主要介紹了opencv車道線檢測(cè)實(shí)戰(zhàn),效果非常逼真,代碼簡(jiǎn)單易懂,對(duì)opencv車道線檢測(cè)實(shí)戰(zhàn)代碼感興趣的朋友一起看看吧
    2022-03-03
  • C++的template模板中class與typename關(guān)鍵字的區(qū)別分析

    C++的template模板中class與typename關(guān)鍵字的區(qū)別分析

    這篇文章中我們來談一談C++的template模板中class與typename關(guān)鍵字的區(qū)別分析,同時(shí)會(huì)講到嵌套從屬名稱時(shí)的一些注意點(diǎn),需要的朋友可以參考下
    2016-06-06
  • C語言中實(shí)現(xiàn)KMP算法的實(shí)例講解

    C語言中實(shí)現(xiàn)KMP算法的實(shí)例講解

    KMP算法即字符串匹配算法,C語言中KMP可以避免指針回溯從而達(dá)到高效,接下來就來總結(jié)一下C語言中實(shí)現(xiàn)KMP算法的實(shí)例講解
    2016-06-06
  • 最新評(píng)論

    永安市| 新田县| 东海县| 靖西县| 邓州市| 元朗区| 静宁县| 英山县| 张家川| 宜宾市| 丹东市| 土默特左旗| 延庆县| 岳阳市| 棋牌| 咸丰县| 大安市| 兰溪市| 玛曲县| 晴隆县| 百色市| 柯坪县| 磴口县| 鄯善县| 龙泉市| 宾川县| 湛江市| 巍山| 邹平县| 独山县| 平南县| 乐都县| 云梦县| 花垣县| 佛教| 合江县| 潞城市| 临夏市| 开阳县| 南郑县| 武宣县|