myname0

практика_пары1_4

Jul 2nd, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include <algorithm>
  2. #include <utility>
  3. #include <fstream>
  4. #include <vector>
  5. #include <math.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. ofstream out("output.txt");
  11.  
  12. bool diag (pair<int,int> a)
  13. {
  14.         return (a.second == a.first);
  15. }
  16.  
  17. bool eq(pair<int,int> a, pair <int, int> b)
  18. {
  19.         return a.first < b.first;
  20. }
  21.  
  22. bool comp (pair<int,int> a)
  23. {
  24.         return (a.first > 0 && a.second < 0);
  25. }
  26.  
  27. bool comparator(pair <int,int> a, pair <int, int> b)
  28. {
  29.        
  30.         return ( a.first * a.first + a.second * a.second <  b.first * b.first + b.second * b.second ) ;
  31. }
  32. void fun(pair <int, int> b, int tmp)
  33. {
  34.         if(b.first * b.first + b.second * b.second == tmp)
  35.                 out << "(" << b.first << ", " << b.second << ")  ";
  36. }
  37. void print(pair <int, int> a)
  38. {
  39.     out << "(" << a.first << ", " << a.second << ")"<< endl;
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45.         ifstream in("input.txt");
  46.        
  47.  
  48.         vector <pair<int, int>> vec;
  49.         int n;
  50.         int m;
  51.         while(in.peek() != EOF)
  52.         {
  53.                 in >> n>> m;
  54.                 vec.push_back(make_pair(n, m));
  55.         }
  56.         vec.erase(remove_if(vec.begin(), vec.end(), comp), vec.end());
  57.         out << "All points without the fourth quater:" << endl;
  58.         for_each(vec.begin(), vec.end(), print);
  59.         out << " count of points on x=y: " << count_if(vec.begin(),vec.end(),diag) << endl;
  60.         vector <pair<int, int>>::iterator it = min_element(vec.begin(), vec.end(), comparator);
  61.         int temp = it->first*(*it).first + it->second * it->second;
  62.         out << "the least distance point(s): ";
  63.         for_each(vec.begin(), vec.end(), bind2nd(ptr_fun(fun), temp));
  64.         out << endl;
  65.         stable_sort(vec.begin(), vec.end(), eq);
  66.         out << " sort:" << endl;
  67.         for_each(vec.begin(), vec.end(), print);
  68.         return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment