C++ //练习 11.9 定义一个map,将单词与一个行号的list关联,list中保存的是单词所出现的行号。

C++ Primer(第5版) 练习 11.9

练习 11.9 定义一个map,将单词与一个行号的list关联,list中保存的是单词所出现的行号。

环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp 复制代码
/*************************************************************************
	> File Name: ex11.9.cpp
	> Author: 
	> Mail: 
	> Created Time: Wed 03 Apr 2024 08:59:10 AM CST
 ************************************************************************/

#include<iostream>
#include<list>
#include<map>
#include<string>
using namespace std;

int main(){
    map<string, list<int>> words;
    list<int> num = {1, 2, 3, 4, 5, 6};
    string word = "compare";

    for(const auto n : num){
        words[word].push_back(n);
    }

    cout<<"words    Line"<<endl;
    for(const auto w: words){
        for(const auto l : w.second){
            cout<<w.first<<"    "<<l<<endl;
        }
    }

    return 0;
}
运行结果显示如下
相关推荐
冬奇Lab1 天前
【Kotlin系列09】委托机制与属性委托实战:组合优于继承的最佳实践
android·开发语言·kotlin
txinyu的博客1 天前
手写 C++ 高性能 Reactor 网络服务器
服务器·网络·c++
Vallelonga1 天前
浅谈 Rust bindgen 工具
开发语言·rust
ElfBoard1 天前
ElfBoard技术贴|如何在ELF-RK3506开发板上构建AI编程环境
c语言·开发语言·单片机·嵌入式硬件·智能路由器·ai编程·嵌入式开发
洲星河ZXH1 天前
Java,泛型
java·开发语言·windows
木木木一1 天前
Rust学习记录--C13 Part1 闭包和迭代器
开发语言·学习·rust
木木木一1 天前
Rust学习记录--C13 Part2 闭包和迭代器
开发语言·学习·rust
Wcy30765190661 天前
文件包含漏洞及PHP伪协议
开发语言·php
Deepoch1 天前
Deepoc数学大模型:通信行业智能化的算法引擎
人工智能·算法·数学建模·开发板·通信·具身模型·deepoc
CopyProfessor1 天前
Java Agent 入门项目模板(含代码 + 配置 + 说明)
java·开发语言