zoukankan      html  css  js  c++  java
  • multimap-count

    ////////////////////////////////////////
    //      2018/05/02 18:46:10
    //      multimap-count
    
    // return the number of elements
    #include <iostream>
    #include <map>
    #include <string>
    #include <fstream>
    
    using namespace std;
    
    int main(){
        typedef multimap<char, string> M1;
        typedef M1::value_type v_t1;
        M1 m1;
    
        typedef multimap<string, char, less<string>> M2;
        typedef M2::value_type v_t2;
        M2 m2;
    
        string word;
        int count = 0;
    
        ifstream in(".\word.txt");
        //如果当前流没有发生错误,函数good()返回true ,否则返回false
        if (in.good()){
            while (1){
                getline(in, word);
                char ch = word.at(0);
                // file is sorted
                if (ch != 'A' && ch != 'a'){
                    break;
                }else{
                    // for conting of words
                    m1.insert(v_t1(ch,word));
                    // for upper-lower bound
                    m2.insert(v_t2(word,ch));
                }
                count++;
            }
            in.close();
        }
    
        cout << "System Dictionary consists " << count
            << " words,
    with first letter 'a' or 'A'"
            << endl;
        cout << m1.count('A') << " words start with 'A'"
            << endl;
        cout << m1.count('a') << " words start with 'a'"
            << endl;
    
        M2::iterator low = m2.lower_bound("aba");
        M2::iterator upp = m2.upper_bound("ace");
        cout << "Range of the words from words 'aba' to 'ace':" << endl;
    
        while (low != upp){
            cout << low->first << endl;
            low++;
        }
        return 0;
    }
    
    /*
    OUTPUT:
        System Dictionary consists 61 words,
        with first letter 'a' or 'A'
        14 words start with 'A'
        47 words start with 'a'
        Range of the words from words 'aba' to 'ace':
        aback
        abase
        abash
        abate
        abbey
        abet
        abhor
        abide
        able
        about
        above
        abuse
        abyss
    */ 

    配套word.txt下载
    https://download.csdn.net/download/qwq1503/10387744

  • 相关阅读:
    cnblogs 博客园下载工具
    SQL 排序规则 CodeProject
    SQL 排序规则问题
    Datatbel和 string之间的相互转换
    C#三步实现标准事件处理程序
    利用C#来做ASP.NET的登陆页面
    C#用panel实现子窗体的切换
    C#中split分隔字符串的应用
    C#.NET 用程序画图,曲线图
    C#中消息的工作流程
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537840.html
Copyright © 2011-2022 走看看