• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ivy-jie

            progress ...

            C++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
              9 Posts :: 41 Stories :: 6 Comments :: 0 Trackbacks
            題目描述:請(qǐng)編寫程序,從包含大量單詞的文本中刪除出現(xiàn)次數(shù)最少的單詞。如果有多個(gè)單詞都出現(xiàn)最少的次數(shù),則將這些單詞都刪除。       輸入數(shù)據(jù):程序讀入已被命名為corpus.txt的一個(gè)大數(shù)據(jù)量的文本文件,該文件包含英文單詞和中文單詞,詞與詞之間以一個(gè)或多個(gè)whitespace(制表符、空格符和換行符一般被統(tǒng)稱為“白字符”(whitespace   characters))分隔。(為便于調(diào)試,您可下載測(cè)試corpus.txt文件,實(shí)際運(yùn)行時(shí)我們會(huì)使用不同內(nèi)容的輸入文件。)       輸出數(shù)據(jù):在標(biāo)準(zhǔn)輸出上打印刪除了corpus.txt中出現(xiàn)次數(shù)最少的單詞之后的文本(詞與詞保持原來的順序,仍以空格分隔)。       
              評(píng)分標(biāo)準(zhǔn):  
              程序輸出結(jié)果必須正確,內(nèi)存使用越少越好,程序的執(zhí)行時(shí)間越快越好  
            #include<iostream>
            #include<fstream>
            #include<map>
            #include<vector>
            #include<string>
            #include<cstring>
            #include<cstdlib>
            #include<iterator>
            #include<algorithm>
            #include<cctype>
            using namespace std;

            typedef map<string,int>::iterator mit;
            typedef string::size_type sit;

            int main()
            {
            map<string,int> words_count;
            vector<string> sve;
            string word;
            string s=",!?.:""\n;'";
            ifstream fin("E:\\corpus.txt");
            if(!fin)
            {
               cerr<<"unable to open file"<<endl;
               exit(0);
            }
            //讀取并統(tǒng)計(jì)單詞單詞
            while(fin>>word)
               {
                sit iter=word.find_first_of(s);
                if(iter!=string::npos)
                  word=word.substr(0,iter-0); //處理標(biāo)點(diǎn)符號(hào)
                string temp(strlwr(const_cast<char*>(word.c_str())));
                word=temp;
                sve.push_back(word);
                ++words_count[word];
               }
            fin.close();
              
            //刪除個(gè)數(shù)最少的單詞
            mit i=words_count.begin();
            int n=i->second;
            for(;i!=words_count.end();++i)
               if(i->second<n) n=i->second;
            for(mit i=words_count.begin();i!=words_count.end(); )
                 {
                  if(i->second==n)
                  {
                   sve.erase(remove(sve.begin(),sve.end(),i->first),sve.end());
                   ++i;
                  }
                  else ++i;
                 }
            //輸出到屏幕
            copy(sve.begin(),sve.end(),ostream_iterator<string>(cout," "));
            cout<<endl;
              
            system("pause");
            return 0;
            }

            posted on 2009-05-20 08:46 ivy-jie 閱讀(452) 評(píng)論(0)  編輯 收藏 引用 所屬分類: arithmetic
            精品一二三区久久aaa片| 亚洲精品乱码久久久久久蜜桃图片 | 亚洲AⅤ优女AV综合久久久| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久夜色精品国产噜噜麻豆| 人妻无码久久精品| 一本一本久久aa综合精品| 久久婷婷五月综合成人D啪| 国产精品久久永久免费| 亚洲第一极品精品无码久久| 久久亚洲国产中v天仙www| 久久国产精品成人片免费| 久久亚洲国产成人影院| 国产精品久久久久久久午夜片| 久久精品国产亚洲av日韩| 久久久久久久综合综合狠狠| 精品国产婷婷久久久| 国内精品久久久久影院网站 | 亚洲国产精品无码成人片久久| 色偷偷888欧美精品久久久| 久久久久国产精品人妻| 久久久久女教师免费一区| 美女写真久久影院| 国内精品久久久久久99| av无码久久久久久不卡网站| 要久久爱在线免费观看| 三级片免费观看久久| 国产亚洲精午夜久久久久久| 99国产欧美久久久精品蜜芽 | 亚洲国产成人精品久久久国产成人一区二区三区综 | 国产成人精品综合久久久| 日本加勒比久久精品| 狠狠人妻久久久久久综合蜜桃| 久久精品国产一区| 精品久久综合1区2区3区激情| 久久精品国产亚洲AV大全| 久久精品天天中文字幕人妻| 亚洲va久久久噜噜噜久久| 久久久亚洲欧洲日产国码aⅴ| 精品久久无码中文字幕| 99久久婷婷免费国产综合精品|