Advertisement
intsashka

mz05-6

Apr 27th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <string>
  5. #include <map>
  6. #include <functional>
  7.  
  8. bool compare(Figure *left, Figure *right) {
  9.     return left->get_square() < right->get_square();
  10. }
  11.  
  12. int main() {
  13.     std::vector<Figure*> figures;
  14.     std::map<std::string, std::function<Figure *(std::string)>> plant =
  15.     {
  16.             {"R", Rectangle::make},
  17.             {"C", Circle::make},
  18.             {"S", Square::make}
  19.     };
  20.  
  21.     std::string type;
  22.  
  23.     while (std::cin >> type) {
  24.         std::string param;
  25.         std::getline(std::cin, param);
  26.         figures.push_back(plant[type](param));
  27.     }
  28.     std::stable_sort(figures.begin(), figures.end(), compare);
  29.  
  30.     for (auto it : figures) {
  31.         std::cout << it->to_string() << std::endl;
  32.         delete it;
  33.     }
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement