• <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++博客 首頁 新隨筆 聯系 聚合 管理
              9 Posts :: 41 Stories :: 6 Comments :: 0 Trackbacks
            題目描述:請編寫程序,從包含大量單詞的文本中刪除出現次數最少的單詞。如果有多個單詞都出現最少的次數,則將這些單詞都刪除。       輸入數據:程序讀入已被命名為corpus.txt的一個大數據量的文本文件,該文件包含英文單詞和中文單詞,詞與詞之間以一個或多個whitespace(制表符、空格符和換行符一般被統稱為“白字符”(whitespace   characters))分隔。(為便于調試,您可下載測試corpus.txt文件,實際運行時我們會使用不同內容的輸入文件。)       輸出數據:在標準輸出上打印刪除了corpus.txt中出現次數最少的單詞之后的文本(詞與詞保持原來的順序,仍以空格分隔)。       
              評分標準:  
              程序輸出結果必須正確,內存使用越少越好,程序的執行時間越快越好  
            #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);
            }
            //讀取并統計單詞單詞
            while(fin>>word)
               {
                sit iter=word.find_first_of(s);
                if(iter!=string::npos)
                  word=word.substr(0,iter-0); //處理標點符號
                string temp(strlwr(const_cast<char*>(word.c_str())));
                word=temp;
                sve.push_back(word);
                ++words_count[word];
               }
            fin.close();
              
            //刪除個數最少的單詞
            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) 評論(0)  編輯 收藏 引用 所屬分類: arithmetic
            久久精品综合一区二区三区| 亚洲国产精品综合久久网络| 成人午夜精品无码区久久| 欧美激情精品久久久久久久九九九| 久久AⅤ人妻少妇嫩草影院| 久久久久亚洲爆乳少妇无| 久久国产精品偷99| 欧美性大战久久久久久| 欧美精品国产综合久久| 久久精品亚洲精品国产色婷| 91超碰碰碰碰久久久久久综合| 久久国产热这里只有精品| 久久只这里是精品66| 久久99久久99精品免视看动漫| 国产激情久久久久影院| 久久久久久久久波多野高潮| 国产∨亚洲V天堂无码久久久| 国产精品欧美久久久天天影视| 久久av高潮av无码av喷吹| 亚洲va中文字幕无码久久不卡| 一本伊大人香蕉久久网手机| 四虎国产精品成人免费久久| WWW婷婷AV久久久影片| 99精品国产免费久久久久久下载| 国产精品久久久亚洲| 久久国产亚洲精品| 国内精品久久久久久久久| 无码人妻久久一区二区三区免费 | 久久婷婷五月综合色奶水99啪| 麻豆AV一区二区三区久久 | 欧美日韩中文字幕久久久不卡| 久久久久免费精品国产| 精品久久久无码中文字幕| 麻豆AV一区二区三区久久 | 国产精品久久久久久久人人看| 久久久精品午夜免费不卡| 久久精品国产亚洲av麻豆图片| 久久综合九色综合欧美就去吻| 国产激情久久久久影院老熟女免费| 久久精品a亚洲国产v高清不卡| 中文精品久久久久人妻不卡|