Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <utility>
- #include <fstream>
- #include <vector>
- #include <math.h>
- using namespace std;
- ofstream out("output.txt");
- bool diag (pair<int,int> a)
- {
- return (a.second == a.first);
- }
- bool eq(pair<int,int> a, pair <int, int> b)
- {
- return a.first < b.first;
- }
- bool comp (pair<int,int> a)
- {
- return (a.first > 0 && a.second < 0);
- }
- bool comparator(pair <int,int> a, pair <int, int> b)
- {
- return ( a.first * a.first + a.second * a.second < b.first * b.first + b.second * b.second ) ;
- }
- void fun(pair <int, int> b, int tmp)
- {
- if(b.first * b.first + b.second * b.second == tmp)
- out << "(" << b.first << ", " << b.second << ") ";
- }
- void print(pair <int, int> a)
- {
- out << "(" << a.first << ", " << a.second << ")"<< endl;
- }
- int main()
- {
- ifstream in("input.txt");
- vector <pair<int, int>> vec;
- int n;
- int m;
- while(in.peek() != EOF)
- {
- in >> n>> m;
- vec.push_back(make_pair(n, m));
- }
- vec.erase(remove_if(vec.begin(), vec.end(), comp), vec.end());
- out << "All points without the fourth quater:" << endl;
- for_each(vec.begin(), vec.end(), print);
- out << " count of points on x=y: " << count_if(vec.begin(),vec.end(),diag) << endl;
- vector <pair<int, int>>::iterator it = min_element(vec.begin(), vec.end(), comparator);
- int temp = it->first*(*it).first + it->second * it->second;
- out << "the least distance point(s): ";
- for_each(vec.begin(), vec.end(), bind2nd(ptr_fun(fun), temp));
- out << endl;
- stable_sort(vec.begin(), vec.end(), eq);
- out << " sort:" << endl;
- for_each(vec.begin(), vec.end(), print);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment