Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. bool com(Figure *x, Figure *y)
  10. {
  11.     return x->get_square() < y->get_square();
  12. }
  13.  
  14. int main()
  15. {
  16.     string s;
  17.     int i, k, size;
  18.     vector<Figure *> figures;
  19.     while (getline(cin, s)) {
  20.         size = s.length();
  21.         Figure *x;
  22.         i = 0;
  23.         while (isspace(s[i++])) {
  24.             if (i >= size) {
  25.                 continue;
  26.             }
  27.         }
  28.         k = i + 1;
  29.         while (isspace(s[k++])) {
  30.             if (k >= size) {
  31.                 continue;
  32.             }
  33.         }
  34.         string next = s.substr(k);
  35.         switch (s[i]) {
  36.             case 'R':
  37.                 x = Rectangle::make(next);
  38.                 break;
  39.             case 'C':
  40.                 x = Circle::make(next);
  41.                 break;
  42.             case 'S':
  43.                 x = Square::make(next);
  44.                 break;
  45.             default:
  46.                 continue;
  47.         }
  48.         figures.push_back(x);
  49.     }
  50.     stable_sort(figures.begin(), figures.end(), com);
  51.     auto it = figures.begin();
  52.     for (; it != figures.end(); ++it) {
  53.         cout << (*it)->to_string() << endl;
  54.     }
  55.     for (it = figures.begin(); it != figures.end(); ++it) {
  56.         delete (*it);
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement