Created
June 14, 2017 05:23
-
-
Save jason790228/32b903f3ffa1bb8bf412f6b9fdacc78c to your computer and use it in GitHub Desktop.
10242
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 10242.cpp : 定義主控台應用程式的進入點。 | |
// | |
#include "stdafx.h" | |
#include <iostream> | |
#include <map> | |
#include <vector> | |
#include <algorithm> | |
#include <string> | |
#include <sstream> | |
#include <iomanip> | |
using namespace std; | |
class Point | |
{ | |
public: | |
double x; | |
double y; | |
Point(double x_coor, double y_coor) | |
{ | |
x = x_coor; | |
y = y_coor; | |
} | |
bool operator < (const Point& point) const | |
{ | |
if (this->x < point.x) return true; | |
if (this->x > point.x) return false; | |
if (this->x == point.x) | |
{ | |
if (this->y < point.y) return true; | |
if (this->y > point.y) return false; | |
} | |
return false; | |
} | |
Point operator + (const Point& point) const | |
{ | |
Point result(0, 0); | |
result.x = this->x + point.x; | |
result.y = this->y + point.y; | |
return result; | |
} | |
Point operator - (const Point& point) const | |
{ | |
Point result(0, 0); | |
result.x = this->x - point.x; | |
result.y = this->y - point.y; | |
return result; | |
} | |
}; | |
bool find_dupication_point(map<Point, bool> &points, Point point) | |
{ | |
map<Point, bool>::iterator it; | |
it = points.find(point); | |
if (it == points.end()) | |
{ | |
points[point] = false; | |
return false; | |
} | |
points[point] = true; | |
return true; | |
} | |
Point compute_fourth_point(map<Point, bool> &points) | |
{ | |
Point result(0, 0); | |
for (auto const &point : points) (point.second) ? (result = result - point.first) : (result = result + point.first); | |
return result; | |
} | |
Point run(vector<double> input) | |
{ | |
map<Point, bool> points; | |
for (int i = 0; i < 8; i += 2) find_dupication_point(points, Point(input[i], input[i + 1])); | |
Point result(0, 0); | |
result = compute_fourth_point(points); | |
return result; | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
string input; | |
vector<double> inputs; | |
while (getline(cin, input)) | |
{ | |
if (input == "") break; | |
istringstream iss(input); | |
for (double s; iss >> s;) inputs.push_back(s); | |
Point result(0, 0); | |
result = run(inputs); | |
cout << fixed << setprecision(3) << result.x << " " << result.y << endl; | |
inputs.clear(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment