728x90
https://www.acmicpc.net/problem/11758
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x1, y1, x2, y2, x3, y3;
StringTokenizer st = new StringTokenizer(br.readLine());
x1 = Integer.parseInt(st.nextToken()); y1 = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
x2 = Integer.parseInt(st.nextToken()); y2 = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
x3 = Integer.parseInt(st.nextToken()); y3 = Integer.parseInt(st.nextToken());
br.close();
int value = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
System.out.println(value > 0 ? 1 : value < 0 ? -1 : 0);
}
}
public class Main {
private static int ccw(int x1, int y1, int x2, int y2, int x3, int y3) { // CounterClockWise
int value = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
return value < 0 ? -1 : value > 0 ? 1 : 0;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int xy[][] = new int[3][2], i, j;
for (i = 0; i < 3; ++i) {
st = new StringTokenizer(br.readLine());
for (j = 0; j < 2; ++j)
xy[i][j] = Integer.parseInt(st.nextToken());
}
br.close();
System.out.println(ccw(xy[0][0], xy[0][1], xy[1][0], xy[1][1], xy[2][0], xy[2][1]));
}
}
반응형
'코딩 문제 풀기 ( Algorithm problem solving ) > 백준 온라인 저지 ( BOJ )' 카테고리의 다른 글
[백준(Baekjoon)][자바(java)] 17386 : 선분 교차 1 / 기하 (0) | 2021.11.27 |
---|---|
[백준(Baekjoon)][자바(java)] 6487 : 두 직선의 교차 여부 / 기하 (0) | 2021.11.27 |
[백준(Baekjoon)][자바(java)] 11080 : Almost an Anagram (0) | 2021.11.08 |
[백준(Baekjoon)][자바(java)] 7587 : Anagram (0) | 2021.11.07 |
[백준(Baekjoon)][자바(java)] 1919 : 애너그램 만들기 (0) | 2021.11.06 |