wrcs | 2021-02-17 10:25:16 UTC | #1
https://pl.spoj.com/problems/PP0506A/
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
class Point {
protected:
string name;
short coordinateX;
short coordninateY;
public:
Point(const string &name, const short &x, const short &y) : coordinateX(x), coordninateY(y) {
this->name = {name};
};
[[nodiscard]] short getCoordniateX() const {
return coordinateX;
}
[[nodiscard]]constexpr short getCoordniateY() const {
return coordninateY;
}
string getName() {
return name;
}
[[nodiscard]] short calculateDistanceBetweenPoints(const short &x, const short &y) const {
return static_cast<short>(sqrt(
pow(coordinateX - x, 2)
+
pow(coordninateY - y, 2)));
}
};
int main() {
short tests;
cin >> tests;
while (tests-- > 0) {
short numberOfPoints;
cin >> numberOfPoints;
vector<Point> points;
while (numberOfPoints-- > 0) {
string nameOfPoint;
short coordinateX, coordinateY;
cin >> nameOfPoint >> coordinateX >> coordinateY;
points.emplace_back(nameOfPoint, coordinateX, coordinateY);
}
sort(points.begin(), points.end(), [](const Point &lhs, const Point &rhs) {
return lhs.calculateDistanceBetweenPoints(0, 0) < rhs.calculateDistanceBetweenPoints(0, 0);
});
for (auto &point : points) {
cout << point.getName() << ' ' << point.getCoordniateX() << ' ' << point.getCoordniateY() << endl;
}
}
return 0;
}
Nieznajomy11 | 2021-01-22 12:53:42 UTC | #2
Jak co naprawić? Jakiś dokładniejszy opis problemu? Wypróbowane do tej pory rozwiązania?
wrcs | 2021-01-22 12:54:53 UTC | #3
wysyłam rozwiązanie i pojawia się błędna odpowiedź.
samemu wpisywałem różne wartości, wszystko było dobrze
Nieznajomy11 | 2021-01-22 13:00:54 UTC | #4
Ok, teraz widzę - przez link do pastebina nie zauważyłem, że nawet wysłałeś już jakiś kod. Skopiowałem go do wątku tak, aby nikt inny nie miał z tym problemu teraz i w ewentualnej przyszłości.
system | 2021-02-23 13:00:54 UTC | #5
Ten temat został automatycznie zamknięty 32 dni po ostatnim wpisie. Tworzenie nowych odpowiedzi nie jest już możliwe.