Advertisement
semkaegor4ik

algorithm 2

Jul 2nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. //Алгоритм б
  2. //подсчитать количество точек, лежащих ниже оси x
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <functional>
  9. using namespace std;
  10. ifstream in("input.txt");
  11. ofstream out("output.txt");
  12. struct Point                                    //структура точки
  13. {
  14. public:
  15.     int x;
  16.     int y;
  17.     Point(int x, int y)                         //конструктор точки
  18.     {
  19.         this->x = x;
  20.         this->y = y;
  21.     }
  22. };
  23.  
  24. int main()
  25. {
  26.     Point a(0, 0);                              //вектор, с которым сравниваются точки
  27.     setlocale(LC_ALL, "ru");
  28.     vector <Point> p;
  29.     int x, y;
  30.     while (in >> x >> y)                        //заполняем вектор
  31.     {
  32.         p.push_back(*new Point(x, y));
  33.     }
  34.     if (p.empty())
  35.         out << "файл пуст";
  36.     else
  37.     {
  38.         vector <Point>::iterator i = p.begin();     //ставим итератор на начало
  39.         auto kolvo = count_if(p.begin(), p.end(), [a](Point b)
  40.         {
  41.             return (a.y > b.y);                     //если значение y меньше, чем у точки а,
  42.                                                     //то прибавляем значение к kolvo
  43.         });
  44.         out << kolvo;                               //выводим кол-во точек
  45.     }
  46.     out.close();
  47.     in.close();
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement