Hello guys, i have a problem and I cant see the solution. I have this program in c++ and i'm trying to solve the following problem:
spoj.com/problems/SORT2D/
My program works fine for the output and I cant find the mistake because it's throwing Wrong Answer, but for the following input its working okey.
Please, i would appreciate any help.
Thank you very much. I'm dying over here
This is my code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <iterator>
using namespace std;
vector <pair <double, double> > arrayWhole;
class sort_pred
{
public:
bool operator()(const pair <double, double> &right, const pair <double, double> &left) const {
if ((left.first > right.first) || (left.first == right.first && left.second < right.second))
{
return left > right;
}
}
};
void sortPoints()
{
sort(arrayWhole.begin(), arrayWhole.end(), sort_pred());
}
int main()
{
int numberTests = 0;
scanf("%d",&numberTests);
double size = 0;
scanf("%Lf", &size);
int start = 0;
while (start < numberTests)
{
double tmpNumber1, tmpNumber2;
for (int i = 0; i < size; i++)
{
scanf("%Lf %Lf", &tmpNumber1, &tmpNumber2);
arrayWhole.push_back(make_pair(tmpNumber1, tmpNumber2));
}
sortPoints();
for (int x = 0; x < arrayWhole.size(); ++x )
{
cout << arrayWhole[x].first << " " << arrayWhole[x].second<<endl;
cout <<endl;
}
arrayWhole.clear();
start++;
}
system("PAUSE");
return 0;
}