Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Алгоритм б
- //подсчитать количество точек, лежащих ниже оси x
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <fstream>
- #include <iomanip>
- #include <functional>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- struct Point //структура точки
- {
- public:
- int x;
- int y;
- Point(int x, int y) //конструктор точки
- {
- this->x = x;
- this->y = y;
- }
- };
- int main()
- {
- Point a(0, 0); //вектор, с которым сравниваются точки
- setlocale(LC_ALL, "ru");
- vector <Point> p;
- int x, y;
- while (in >> x >> y) //заполняем вектор
- {
- p.push_back(*new Point(x, y));
- }
- if (p.empty())
- out << "файл пуст";
- else
- {
- vector <Point>::iterator i = p.begin(); //ставим итератор на начало
- auto kolvo = count_if(p.begin(), p.end(), [a](Point b)
- {
- return (a.y > b.y); //если значение y меньше, чем у точки а,
- //то прибавляем значение к kolvo
- });
- out << kolvo; //выводим кол-во точек
- }
- out.close();
- in.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement