일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- Spring boot
- 리눅스
- 코딩테스트
- java
- sql
- 싱글톤
- 반복문
- html
- 시큐리티 로그아웃
- springSecurity
- 시큐리티로그인
- 프로그래머스
- JAVA11
- 2차원배열
- javascript
- springboot
- 시큐리티 로그인
- 소스트리
- Linux
- codingtest
- 시큐리티
- 로그인
- programmers
- css
- security
- StyleSheet
- 스프링 부트
- 목록
- input태그
- gradle
Archives
- Today
- Total
JAVAIARY
프로그래머스) 평행 본문
문제: https://school.programmers.co.kr/learn/courses/30/lessons/120875
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
public int solution(int[][] dots) {
int answer = 0;
for (int i = 1; i < dots.length; i++) {
double x = dots[0][0] - dots[i][0];
double y = dots[0][1] - dots[i][1];
double incl1 = (dots[0][1] - dots[i][1]) / (dots[0][0] - dots[i][0]);
int j = i == 3 ? 1 : 0;
double x1 = dots[3 - j][0] - dots[3 - i + j][0];
double y1 = dots[3 - j][1] - dots[3 - i + j][1];
double incl2 = (dots[3 - j][1] - dots[3 - i + j][1]) / (dots[3 - j][0] - dots[3 - i + j][0]);
System.out.println("incl1 : " + incl1 + "incl2 : " + incl2);
if (Math.pow(incl1, 2) == Math.pow(incl2, 2)) {
answer = 1;
break;
}
}
return answer;
}
}
- x1, y1 의 좌표를 찾는 데 고민을 좀 했다.
- 절댓값 비교를 하려고 그냥 제곱해버림
'examplePractice' 카테고리의 다른 글
프로그래머스 ) 두 개 뽑아서 더하기 (0) | 2023.05.29 |
---|---|
프로그래머스 ) 소수 찾기 (0) | 2023.04.19 |
프로그래머스) 두 정수 사이의 합 (0) | 2023.04.19 |
프로그래머스) 자연수 뒤집어 배열로 만들기 (0) | 2023.04.18 |
프로그래머스 ) 이상한 문자 만들기 (0) | 2023.04.10 |