Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <sstream>
- #include <cmath>
- class Figure {
- public:
- virtual double get_square () const = 0;
- virtual ~Figure() {};
- };
- class Rectangle : public Figure {
- double a;
- double b;
- Rectangle (double a, double b) : a(a), b(b) {};
- public:
- double get_square () const {
- return a * b;
- }
- static Rectangle * make (std::string s) {
- double x, y;
- std::stringstream ss;
- ss << s;
- ss >> x;
- ss >> y;
- Rectangle *p = new Rectangle(x, y);
- return p;
- }
- std::string to_string () {
- std::string s;
- std::stringstream ss;
- ss << a << ' ' << b;
- ss >> s;
- return s;
- }
- };
- class Square : public Figure {
- double a;
- Square (double a) : a(a) {};
- public:
- double get_square () const {
- return a * a;
- }
- static Square * make (std::string s) {
- double x;
- std::stringstream ss;
- ss << s;
- ss >> x;
- Square *p = new Square(x);
- return p;
- }
- std::string to_string () {
- std::string s;
- std::stringstream ss;
- ss << a;
- ss >> s;
- return s;
- }
- };
- class Circle : public Figure {
- double r;
- Circle (double r) : r(r) {};
- public:
- double get_square () const {
- return r * r * M_PI;
- }
- static Circle * make (std::string s) {
- double x;
- std::stringstream ss;
- ss << s;
- ss >> x;
- Circle *p = new Circle(x);
- return p;
- }
- std::string to_string () {
- std::string s;
- std::stringstream ss;
- ss << as;
- ss >> s;
- return s;
- }
- };
- bool operator< (const Figure &a, const Figure &b) {
- return get_square(a) < get_square(b);
- }
- int main() {
- std::string s;
- char type;
- double x, y;
- vector <Figure> v;
- while (std::getline(cin, s)) {
- std::stringstream ssr;
- std::stringstream ssw;
- ssr << s;
- ssr >> type;
- if (type == 'R') {
- ssr >> x >> y;
- ssw << x << ' ' << y;
- ssw >> s;
- Rectangle * p = Rectangle::make(s);
- } else if(type == 'S') {
- ssr >> x;
- ssw << x;
- ssw >> s;
- Square * p = Square::make(s);
- } else {
- ssr >> x;
- ssw << x;
- ssw >> s;
- Circe * p = Circle::make(s);
- }
- v.push_back(p);
- }
- std::stable_sort(v.begin(), v.end());
- for (auto i = v.begin(); i != v.end(); ++i) {
- std::cout << i->to_string() << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement