为了账号安全,请及时绑定邮箱和手机立即绑定

C++ 关于map容器的一道编程题请教?

/ 猿问

C++ 关于map容器的一道编程题请教?

九州编程 2018-10-01 13:09:51

C++ 关于map容器的一道编程题请教




查看完整描述

1 回答

?
ITMISS

#include <map>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main()
{
map<string, vector<string>> Families;
vector<string> Children;
Children.push_back("红娃");
Children.push_back("橙娃");
Children.push_back("黄娃");
Children.push_back("绿娃");
Children.push_back("青娃");
Children.push_back("蓝娃");
Children.push_back("紫娃");

Families.insert(make_pair<string, vector<string>>("Zhao",Children));
Families.insert(make_pair<string, vector<string>>("Qian",Children));
Families.insert(make_pair<string, vector<string>>("Sun",Children));
Families.insert(make_pair<string, vector<string>>("Li",Children));
Families.insert(make_pair<string, vector<string>>("Zhou",Children));
Families.insert(make_pair<string, vector<string>>("Wu",Children));
Families.insert(make_pair<string, vector<string>>("Zheng",Children));
Families.insert(make_pair<string, vector<string>>("Wang",Children));

//
string Xing;
cin >> Xing;

//查找葫芦娃
auto iter = Families.find(Xing);
if (iter==Families.end())
cout << "没有找到姓" + Xing + "的葫芦娃" << endl;
else
{
vector<string> Huluwa = iter->second;
cout << "找到姓" + Xing + "的葫芦娃:" << endl;
for (unsigned i=0; i<Huluwa.size(); i++)
{
cout << Xing + Huluwa[i] << endl;
}
}

system("pause");
return 0;
}

查看完整回答
反对 回复 2018-10-06

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信