Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. class Point {
  2. private:
  3. string name_;
  4. double x_, y_;
  5. public:
  6. Point(string name, double x, double y) : name_(name), x_(x), y_(y){}
  7. Point() {}
  8.  
  9. double getSum() { return x_ + y_;}
  10.  
  11. string getName() { return name_;}
  12. double getX() { return x_;}
  13. double getY() { return y_;}
  14.  
  15. };
  16. ///////////////////////////////
  17. ostream & operator<<(ostream & s, Point & object) {
  18. return s << object.getName() << " " << object.getX() << " " << object.getY() << " ";
  19. }
  20. ///////////////////////////////
  21. int size;
  22. bool operator<(Point object1, Point object2) {
  23. if(object1.getSum() == object2.getSum()) {
  24. if(object1.getX() == object2.getX()) {
  25. if(object1.getName().size() < object2.getName().size())
  26. size = object1.getName().size();
  27. else
  28. size = object2.getName().size();
  29.  
  30. for(int i = 0; i<size; i++) {
  31. if(object1.getName()[i] != object2.getName()[i])
  32. return object1.getName()[i] < object2.getName()[i];
  33. }
  34. }
  35. return (object1.getX() < object2.getX());
  36. }
  37. return object1.getSum() < object2.getSum();
  38. }
  39.  
  40.  
  41. // ======================================================================
  42. // main
  43. // ======================================================================
  44.  
  45. int main() {
  46.  
  47. string name;
  48. double x, y;
  49.  
  50. list<Point> pList;
  51. Iterator <Point> pIterator(pList);
  52.  
  53. int n;
  54.  
  55. cin >> n;
  56.  
  57. Point *objects = new Point[n];
  58.  
  59. for(int i = 0; i<n; i++) {
  60. cin >> name >> x >> y;
  61. objects[i] = Point(name, x, y);
  62. }
  63.  
  64. for(int i = 0; i<n-1; i++)
  65. for(int j = 0; j<n-i-1; j++)
  66. if(objects[j]<objects[j+1])
  67. swap(objects[j], objects[j+1]);
  68.  
  69. for(int i = 0; i<n; i++)
  70. pList.add(objects[i]);
  71.  
  72. cin >> x;
  73.  
  74. for(pIterator.init(); !pIterator; pIterator++)
  75. if((pIterator().getSum()) == x)
  76. pIterator.remove_current();
  77.  
  78. for(pIterator.init(); !pIterator; pIterator++) {
  79. objects[0] = pIterator();
  80. cout << objects[0];
  81. }
  82.  
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement