大家好,这里是国中之林!
❥前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。有兴趣的可以点点进去看看←
问题:
解答:
main.cpp
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main()
{
set<string> Mat_set, Pat_set, Guest_set;
cout << "Enter Mat's friends(q to quit): ";
string name;
while (getline(cin,name)&&name!="q")
{
Mat_set.insert(name);
cout << "Enter Mat's friends(q to quit): ";
}
cout << "\nMat's friends are: \n";
for (auto pd = Mat_set.begin(); pd != Mat_set.end(); pd++)
{
cout << *pd << " ";
}
cout << "\nEnter Pat's friends(q to quit): ";
while (getline(cin, name) && name != "q")
{
Pat_set.insert(name);
cout << "Enter Pat's friends(q to quit): ";
}
cout << "\nPat's friends are: \n";
for (auto pd = Pat_set.begin(); pd != Pat_set.end(); pd++)
{
cout << *pd << " ";
}
Guest_set.insert(Mat_set.begin(), Mat_set.end());
Guest_set.insert(Pat_set.begin(), Pat_set.end());
cout << "\n All friends are: \n";
for (auto pd = Guest_set.begin(); pd != Guest_set.end(); pd++)
{
cout << *pd << " ";
}
return 0;
}
运行结果:
考查点:
- set关联容器
- 无重复
- 迭代器
2024年9月18日21:40:43