博客
关于我
c++ primer 5th 练习11.9自己编写的答案
阅读量:305 次
发布时间:2019-03-04

本文共 698 字,大约阅读时间需要 2 分钟。

#include 
#include
#include
#include
#include
#include
//stringstream对象需要包含头文件sstream#include
using namespace std;int main(){map
> word_linenumber;string words;int number = 0;string word;while(getline(cin,words)) { ++ number; stringstream in(words); while(in >> word) word_linenumber[word].push_back(number); }for(const auto & i : word_linenumber) { cout << i.first << ":"; for(auto j : i.second) cout << j << " "; cout << endl; } return 0;}

运行结果:

i am a goodboy and you are a good boytoo so you are a good boya:1 3 4 am:1 and:2 are:3 4 boy:2 3 5 good:1 3 5 i:1 so:4 too:4 you:2 4

总结:list也可以使用push_back()在末尾添加元素

转载地址:http://yfvq.baihongyu.com/

你可能感兴趣的文章
jQuery练习t90
查看>>
jQuery练习t110
查看>>
jQuery练习t123
查看>>
jQuery练习t167,从0到1
查看>>
jQuery练习t271,从0到1
查看>>
jQuery练习t310,从0到1
查看>>
asp.net代码练习 work015 回调技术
查看>>
asp.net代码练习 work016 fileupload文件上传
查看>>
asp.net代码练习 work021 DataReader的使用
查看>>
PHP7.0--如何使用函数的引用
查看>>
Java基础--01--数据类型/方法/数组
查看>>
【JokerのZYNQ7020】LINUX_EMIO_LED。
查看>>
【JokerのZYNQ7020】LINUX_EMIO_BUTTON。
查看>>
vim匹配特定的行并删除
查看>>
读取excel文件错误
查看>>
傅里叶变换的初级理解三
查看>>
F1 score的意义
查看>>
python36+centos7离线安装tensorflow与talib的方法
查看>>
hdf5与hdfs的区别
查看>>
scala运行的方式
查看>>