상세 컨텐츠

본문 제목

정사각형

코딩테스트

by dofury 2023. 5. 9. 20:53

본문

728x90

import java.awt.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;

public class Main {
    public static void main(String[] args) throws IOException {


        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int count = Integer.parseInt(br.readLine());
        for(int i = 0; i < count; i++) {

            ArrayList<Point> points = new ArrayList<Point>();
            ArrayList<Double> lengths = new ArrayList<Double>();

            for(int j = 0; j < 4; j++) {//좌표 추가

                String[] line = br.readLine().split(" ");
                points.add(new Point(Integer.parseInt(line[0]), Integer.parseInt(line[1])));

            }

            for(int j = 0; j<4;j++){

                for(int k = j+1 ; k<4;k++){

                    double length = 0;
                    length = Math.sqrt(Math.pow(points.get(j).x - points.get(k).x,2) + Math.pow(points.get(j).y - points.get(k).y,2));
                    lengths.add(length);

                }

            }

            Collections.sort(lengths);
            Collections.reverse(lengths);

            if(Objects.equals(lengths.get(0), lengths.get(1)) && Objects.equals(lengths.get(2), lengths.get(3)) && Objects.equals(lengths.get(2), lengths.get(4)) && Objects.equals(lengths.get(2), lengths.get(5))  ){
                bw.write(String.valueOf(1));
                bw.newLine();
            }else{
                bw.write(String.valueOf(0));
                bw.newLine();
            }
        }

        bw.flush();
        br.close();
        bw.close();
    }
}

https://www.acmicpc.net/problem/1485

728x90

'코딩테스트' 카테고리의 다른 글

명령 프롬프트  (0) 2023.05.12
  (0) 2023.05.12
단어 정렬  (0) 2023.05.09
나는 요리사다  (0) 2023.05.09
수리공 항승  (0) 2023.05.09

관련글 더보기

댓글 영역