您的位置:首页 > 汽车 > 新车 > 企业管理咨询心得体会_网站平台开发与应用面试_企业站seo外包_搜索引擎的工作原理是什么

企业管理咨询心得体会_网站平台开发与应用面试_企业站seo外包_搜索引擎的工作原理是什么

2024/9/21 5:19:00 来源:https://blog.csdn.net/qq_74047911/article/details/142404720  浏览:    关键词:企业管理咨询心得体会_网站平台开发与应用面试_企业站seo外包_搜索引擎的工作原理是什么
企业管理咨询心得体会_网站平台开发与应用面试_企业站seo外包_搜索引擎的工作原理是什么

大家好,这里是国中之林!
❥前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。有兴趣的可以点点进去看看←

问题:

在这里插入图片描述

解答:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <memory>
using namespace std;struct Review
{string title;int rating;int price;
};bool operator<(const shared_ptr<Review>& p1, const shared_ptr<Review>& p2);
bool FillReview(Review& rr);
void ShowReview(const shared_ptr<Review>& p);
bool worseThan(const shared_ptr<Review>& p1, const shared_ptr<Review>& p2);
bool expenThan(const shared_ptr<Review>& p1, const shared_ptr<Review>& p2);int main()
{vector<shared_ptr<Review>>books;Review temp;while (FillReview(temp)){shared_ptr<Review>pd(new Review(temp));books.push_back(pd);}if (books.size() > 0){cout << "Choose the way to sort: "<< "r:rate, s: rate r, p:price, d:price, d:price r, q:quit\n";char choice;while (cin >> choice && choice != 'q'){switch (choice){case 'r':sort(books.begin(), books.end(), worseThan);break;case 's':sort(books.rbegin(), books.rend(), worseThan);break;case 'p':sort(books.begin(), books.end(), expenThan);break;case 'd':sort(books.rbegin(), books.rend(), expenThan);break;default:break;}for_each(books.begin(), books.end(), ShowReview);cout<<"Please choose the way to sort: "<< "r:rate, s: rate r, p:price, d:price, d:price r, q:quit\n";}}return 0;
}bool operator<(const shared_ptr<Review>& p1, const shared_ptr<Review>& p2)
{if (p1->title < p2->title)return true;else if (p1->title == p2->title && p1->rating < p2->rating)return true;elsereturn false;
}
bool FillReview(Review& rr)
{cout << "Enter book title (quit to quit): ";getline(cin, rr.title);if (rr.title == "quit" || rr.title == "")return false;cout << "Enter book rating: ";cin >> rr.rating;if (!cin)return false;cout << "Enter book price: ";cin >> rr.price;if (!cin)return false;while (cin.get() != '\n'){continue;}return true;
}
void ShowReview(const shared_ptr<Review>& p)
{cout << p->rating << "\t" << p->title << "\t" << p->price << endl;
}
bool  worseThan(const shared_ptr<Review>& p1, const shared_ptr<Review>& p2)
{if (p1->rating < p2->rating)return true;elsereturn false;
}
bool expenThan(const shared_ptr<Review>& p1, const shared_ptr<Review>& p2)
{if (p1->price < p2->price)return true;elsereturn false;
}

运行结果:
在这里插入图片描述

考查点:

  • vector容器
  • 智能指针
  • sort()
  • 迭代器
  • for_each()

2024年9月20日21:49:47

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com