티스토리 뷰

백준

백준 소스코드 [C++] 11758 CCW

Hani_Levenshtein 2020. 11. 11. 12:06

www.acmicpc.net/problem/11758

 

11758번: CCW

첫째 줄에 P1의 (x1, y1), 둘째 줄에 P2의 (x2, y2), 셋째 줄에 P3의 (x3, y3)가 주어진다. (-10,000 ≤ x1, y1, x2, y2, x3, y3 ≤ 10,000) 모든 좌표는 정수이다. P1, P2, P3의 좌표는 서로 다르다.

www.acmicpc.net

백준 소스코드 [C++] 11758 CCW

#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
typedef long long ll;
using namespace std;
struct dot {
	ll x, y;
};
vector<dot> dots;

int ccw(dot A, dot B, dot C) {
	ll rot = (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y);
	if (rot > 0) return 1;
	else if (rot < 0) return -1;
	else return 0;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	dots.resize(3);
	for (int i = 0;i < 3;i++) cin >> dots[i].x >> dots[i].y;
	cout << ccw(dots[0], dots[1], dots[2]);
	return 0;
}
댓글