Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- bool com(Figure *x, Figure *y)
- {
- return x->get_square() < y->get_square();
- }
- int main()
- {
- string s;
- int i, k, size;
- vector<Figure *> figures;
- while (getline(cin, s)) {
- size = s.length();
- Figure *x;
- i = 0;
- while (isspace(s[i++])) {
- if (i >= size) {
- continue;
- }
- }
- k = i + 1;
- while (isspace(s[k++])) {
- if (k >= size) {
- continue;
- }
- }
- string next = s.substr(k);
- switch (s[i]) {
- case 'R':
- x = Rectangle::make(next);
- break;
- case 'C':
- x = Circle::make(next);
- break;
- case 'S':
- x = Square::make(next);
- break;
- default:
- continue;
- }
- figures.push_back(x);
- }
- stable_sort(figures.begin(), figures.end(), com);
- auto it = figures.begin();
- for (; it != figures.end(); ++it) {
- cout << (*it)->to_string() << endl;
- }
- for (it = figures.begin(); it != figures.end(); ++it) {
- delete (*it);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement