Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Алгоритм г
- //расположить в порядке удаления о начала координат, сохраняя исходный порядок при одинаковом расстоянии
- #include <iostream>
- #include <conio.h>
- #include <algorithm>
- #include <vector>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- class Point //создаем класс точки
- {
- public:
- int x, y;
- Point(int x, int y) //структура класса
- {
- this->x = x;
- this->y = y;
- }
- double GetP() //метод, возвращающий расстояние от начала с.к. до точки
- {
- return sqrt(x * x + y * y);
- }
- friend ostream& operator << (ostream &out, const Point &point); //оператор, выводящий точку
- };
- ostream& operator<< (std::ostream &out, const Point &point)
- {
- out << "(" << setw(2) << point.x << setw(2) << " , " << setw(2) << point.y << setw(2) << ")";
- return out;
- }
- int main()
- {
- setlocale(LC_ALL, "ru");
- vector <Point> p;
- int x, y, max = 0;
- while (in >> x >> y) //заполняем вектор точками
- {
- p.push_back(*new Point(x, y));
- }
- if (p.empty())
- out << "файл пуст";
- sort(p.begin(), p.end(), [](Point a, Point b) //стортируем точки по их расстоянию
- {
- return (a.GetP() < b.GetP());
- });
- for (auto it : p) //выводим элементы вектора
- out << it << endl;
- out.close();
- in.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement