본문 바로가기

코딩 테스트

백준 네번째점

#include <iostream>
using namespace std;

struct Point
{
	long double x, y;

	Point() = default;

	Point(float X, float Y) : x(X), y(Y)
	{

	}

	Point operator+ (const Point& other) const
	{
		return Point(x + other.x, y + other.y);
	}

	Point operator- (const Point& other) const
	{
		return Point(x - other.x, y - other.y);
	}

	bool operator== (const Point& other) const
	{
		return x == other.x && y == other.y;
	}

	bool operator< (const Point& other) const
	{
		return x == other.x || x < other.x && y < other.y;
	}
};

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	struct Point a, b, c, d;

	long double q, w, e, r, t, y, u, i;

	while (cin >> q >> w >> e >> r >> t >> y >> u >> i)
	{
		Point answer;
		a.x = q;
		a.y = w;
		b.x = e;
		b.y = r;
		c.x = t;
		c.y = y;
		d.x = u;
		d.y = i;

		if (a == c) answer = b + d - a;
		else if (a == d) answer = c + b - a;
		else if (b == c) answer = a + d - b;
		else if (b == d) answer = a + c - b;

		cout << fixed;
		cout.precision(3);
		cout << answer.x << " " << answer.y << "\n";
	}

	
	return 0;
}

 

'코딩 테스트' 카테고리의 다른 글

백준 1246  (0) 2024.06.12
백준 11004  (0) 2024.06.11
백준 회전하는 큐  (0) 2024.06.11
귤 고르기  (0) 2024.05.20
프로그래머스 타겟 넘버  (0) 2024.03.04