Coding Test/BaekJoon_C++
백준 11758 <CCW> C++
JunOnJuly
2024. 3. 26. 16:40
728x90
https://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
백준 11758 <CCW> Python
https://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의 좌
dev-diary-0717.tistory.com
파이썬으로 풀었던 문제를 C++ 로 재구성 했습니다.
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
using namespace std;
// ccw 알고리즘
int ccw(vector<int> points) {
// 처음 포인트 뒤에 추가
points.push_back(points[0]);
points.push_back(points[1]);
// 합
long long int sum{};
// 계산
for (int i = 0; i < 3; i++) {
sum += points[i * 2] * points[((i + 1) * 2 + 1)];
sum -= points[(i + 1) * 2] * points[i * 2 + 1];
}
if (sum > 0) return 1;
else if (sum == 0) return 0;
else return -1;
}
int main(void) {
// 입력
vector<int> points;
for (int i = 0; i < 3; i++) {
int x, y;
cin >> x >> y;
points.push_back(x);
points.push_back(y);
}
cout << ccw(points);
}
728x90