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
'Coding Test > BaekJoon_C++' 카테고리의 다른 글
백준 1162 <도로포장> C++ (0) | 2024.03.28 |
---|---|
백준 1451 <직사각형으로 나누기> C++ (2) | 2024.03.27 |
백준 2252 <줄 세우기> C++ (0) | 2024.03.25 |
백준 1717 <집합의 표현> C++ (1) | 2024.03.15 |
백준 11657 <타임머신> C++ (0) | 2024.03.14 |