c++ primer 5th 练习11.7自编答案
发布日期:2021-05-07 00:57:06 浏览次数:19 分类:精选文章

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

#include 
#include
#include
#include
using namespace std;int main(){map
> names;string surname;string child;cout << "enter surname(q to end):" << endl;while(cin >> surname) { if(surname == "q") break; cout << "enter child(q to end):"; cin >> child; if(child == "q") break; names[surname].push_back(child); cout << "enter surname(q to end):"; }for(const auto & it : names) { cout << "surname:" << it.first << endl; cout << "children:" << endl; for(const auto & it1 : it.second) cout << "\t"<< it1 << endl; cout << endl; } return 0;}~ ~

运行结果如下: 

enter surname(q to end):qiaoenter child(q to end):weienter surname(q to end):qiaoenter child(q to end):sanfengenter surname(q to end):yangenter child(q to end):meilienter surname(q to end):yangenter child(q to end):guoenter surname(q to end):qsurname:qiaochildren:	wei	sanfengsurname:yangchildren:	meili	guo

 

上一篇:c++ primer 5th 练习11.9自己编写的答案
下一篇:string中删除一个元素

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年04月01日 19时06分11秒