zoukankan      html  css  js  c++  java
  • multiset-lower_bound

    ////////////////////////////////////////
    //      2018/05/04 17:36:15
    //      multiset-lower_bound
    
    // return an iteror to the first element greater than a certain value
    #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 counter = 0;
    
        ifstream In(".\word.txt");
        if (In.good()){
            while (1){
                getline(In, word);
                char ch = word.at(0);
                // file is sorted
                if (ch != 'A' && ch != 'a'){
                    break;
                }else{
                    // for counting of words
                    m1.insert(v_t1(ch, word));
                    // for upper_lower bound
                    m2.insert(v_t2(word,ch));
                }
                counter++;
            }
            In.close();
        }
    
        cout << "System Dictionary consists " << counter << " word 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("Ade");
    
        cout << "Range of the words form 'Aba' to 'Ade':" << endl;
        while (low != upp){
            cout << low->first << endl;
            low++;
        }
        return 0;
    }
    
    /*
    OUTPUT:
        System Dictionary consists 61 word with first letter 'a' or 'A'
        14 words start with 'A'
        47 words start with 'a'
        Range of the words form 'Aba' to 'Ade':
        Abolish
        Action
        Acute
    */ 
  • 相关阅读:
    SignalRMvc的简单例子
    CTE递归查询
    数据库表设计(邻接表、路径枚举、嵌套集、闭包表)
    EF事务
    context日志
    Context连接和断开的情况下的CRUD操作
    Sql语句拼接(EXEC和sp_executesql的区别)
    实体框架中的变更跟踪
    sql server 添加字段并且赋默认值和说明
    C# .ToString() 格式化
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537828.html
Copyright © 2011-2022 走看看