Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <sstream>
  4. #include <cmath>
  5.  
  6. class Figure {
  7. public:
  8.     virtual double get_square () const = 0;
  9.     virtual ~Figure() {};
  10. };
  11.  
  12. class Rectangle : public Figure {
  13.     double a;
  14.     double b;
  15.     Rectangle (double a, double b) : a(a), b(b) {};
  16. public:
  17.     double get_square () const {
  18.         return a * b;
  19.     }
  20.     static Rectangle * make (std::string s) {
  21.         double x, y;
  22.         std::stringstream ss;
  23.         ss << s;
  24.         ss >> x;
  25.         ss >> y;
  26.         Rectangle *p = new Rectangle(x, y);
  27.         return p;
  28.     }
  29.     std::string to_string () {
  30.         std::string s;
  31.         std::stringstream ss;
  32.         ss << a << ' ' << b;
  33.         ss >> s;
  34.         return s;
  35.     }
  36. };
  37.  
  38. class Square : public Figure {
  39.     double a;
  40.     Square (double a) : a(a) {};
  41. public:
  42.     double get_square () const {
  43.         return a * a;
  44.     }
  45.     static Square * make (std::string s) {
  46.         double x;
  47.         std::stringstream ss;
  48.         ss << s;
  49.         ss >> x;
  50.         Square *p = new Square(x);
  51.         return p;
  52.     }
  53.     std::string to_string () {
  54.         std::string s;
  55.         std::stringstream ss;
  56.         ss << a;
  57.         ss >> s;
  58.         return s;
  59.     }
  60. };
  61.  
  62. class Circle : public Figure {
  63.     double r;
  64.     Circle (double r) : r(r) {};
  65. public:
  66.     double get_square () const {
  67.         return r * r * M_PI;
  68.     }
  69.     static Circle * make (std::string s) {
  70.         double x;
  71.         std::stringstream ss;
  72.         ss << s;
  73.         ss >> x;
  74.         Circle *p = new Circle(x);
  75.         return p;
  76.     }
  77.     std::string to_string () {
  78.         std::string s;
  79.         std::stringstream ss;
  80.         ss << as;
  81.         ss >> s;
  82.         return s;
  83.     }
  84. };
  85.  
  86. bool operator< (const Figure &a, const Figure &b) {
  87.     return get_square(a) < get_square(b);
  88. }
  89.  
  90. int main() {
  91.     std::string s;
  92.     char type;
  93.     double x, y;
  94.     vector <Figure> v;
  95.     while (std::getline(cin, s)) {
  96.         std::stringstream ssr;
  97.         std::stringstream ssw;
  98.         ssr << s;
  99.         ssr >> type;
  100.         if (type == 'R') {
  101.             ssr >> x >> y;
  102.             ssw << x << ' ' << y;
  103.             ssw >> s;
  104.             Rectangle * p = Rectangle::make(s);
  105.         } else if(type == 'S') {
  106.             ssr >> x;
  107.             ssw << x;
  108.             ssw >> s;
  109.             Square * p = Square::make(s);
  110.         } else {
  111.             ssr >> x;
  112.             ssw << x;
  113.             ssw >> s;
  114.             Circe * p = Circle::make(s);
  115.         }
  116.         v.push_back(p);
  117.     }
  118.     std::stable_sort(v.begin(), v.end());
  119.     for (auto i = v.begin(); i != v.end(); ++i) {
  120.         std::cout << i->to_string() << std::endl;
  121.     }
  122.     return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement