diff --git a/code_study/Baekjoon/java/_17387.java b/code_study/Baekjoon/java/_17387.java new file mode 100644 index 0000000..35eac84 --- /dev/null +++ b/code_study/Baekjoon/java/_17387.java @@ -0,0 +1,63 @@ +import java.util.*; + +class Line { + long x1, x2, y1, y2; + + Line(long x1, long y1, long x2, long y2) { + if(x1 > x2 || (x1 == x2 && y1 > y2)) { + x1 = x1^x2; + x2 = x1^x2; + x1 = x1^x2; + + y1 = y1^y2; + y2 = y1^y2; + y1 = y1^y2; + } + + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + } + + public int crossProduct(long x0, long y0) { + long val = (x0-x1)*(y2-y1) - (y0-y1)*(x2-x1); + return val > 0 ? 1 : val < 0 ? -1 : 0; + } +} + +public class _17387 { + static boolean comparePoint(long x1, long y1, long x2, long y2) { + if(x1 < x2) return true; + else if(x1 == x2 && y1 <= y2) return true; + else return false; + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + long x1 = sc.nextLong(), y1 = sc.nextLong(), x2 = sc.nextLong(), y2 = sc.nextLong(); + Line L1 = new Line(x1, y1, x2, y2); + long x3 = sc.nextLong(), y3 = sc.nextLong(), x4 = sc.nextLong(), y4 = sc.nextLong(); + Line L2 = new Line(x3, y3, x4, y4); + + sc.close(); + + int crossABCD = L1.crossProduct(x3, y3) * L1.crossProduct(x4, y4); + int crossCDAB = L2.crossProduct(x1, y1) * L2.crossProduct(x2, y2); + + int res = 0; + + if(crossABCD == 0 && crossCDAB == 0) { + if(comparePoint(L1.x1, L1.y1, L2.x2, L2.y2) && comparePoint(L2.x1, L2.y1, L1.x2, L1.y2)) { + res = 1; + } + } + + else if(crossABCD <= 0 && crossCDAB <= 0) { + res = 1; + } + + System.out.println(res); + } +} diff --git a/code_study/Baekjoon/python/4740.py b/code_study/Baekjoon/python/4740.py new file mode 100644 index 0000000..05cd9c7 --- /dev/null +++ b/code_study/Baekjoon/python/4740.py @@ -0,0 +1 @@ +print("\n".join([s[::-1] for s in iter(input, "***")])) \ No newline at end of file