#include<iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>
int main()
{
vector<string> Mat, Pat, Total;
string name;
cout << "the Mat book title: ";
while (getline(cin, name))
{
Mat.push_back(name);
Total.push_back(name);
if (name[0] == '\0')
break;
}
cout << "the Mat book title: ";
sort(Mat.begin(), Mat.end());
for (auto i = Mat.begin(); i != Mat.end(); i++)
cout << *i << " ";
cout << endl;
cout << "the Pat book title: ";
while (getline(cin, name))
{
Pat.push_back(name);
Total.push_back(name);
if (name[0] == '\0')
break;
}
cout << "the Pat book title: ";
sort(Pat.begin(), Pat.end());
for (auto i = Pat.begin(); i != Pat.end(); i++)
cout << *i << " ";
cout << endl;
sort(Total.begin(), Total.end());
unique(Total.begin(), Total.end());
for (auto i = Total.begin(); i != Total.end(); i++)
cout << *i << " ";
cout << endl;
return 0;
}
第十六章第八题
最新推荐文章于 2024-06-19 14:59:54 发布
本文介绍了一个使用C++实现的简单程序,该程序通过标准输入读取图书标题,并利用vector容器进行存储。程序首先分别收集并排序两组图书标题,然后合并这两组数据并去除重复项,最终输出所有唯一且已排序的图书标题。
25万+

被折叠的 条评论
为什么被折叠?



