import java.util.*;

class Solution {
    public String[] solution(int[][] line) {
        List<Long> xl = new ArrayList<>(); List<Long> yl = new ArrayList<>();
        long xMax = Long.MIN_VALUE; long xMin = Long.MAX_VALUE;
        long yMax = Long.MIN_VALUE; long yMin = Long.MAX_VALUE;
        
        for(int i=0; i<line.length; i++) {
            for(int j=0; j<i; j++) {
                long a = line[i][0]; long b = line[i][1]; long e = line[i][2];
                long c = line[j][0]; long d = line[j][1]; long f = line[j][2];
                double x = (double)(b*f-e*d)/(a*d-b*c); double y = (double)(e*c-a*f)/(a*d-b*c);
                
                if(check(x,y)) { xl.add((long)x); yl.add((long)y); }
            }
        }
        
        for(int i=0; i<xl.size(); i++) {
            xMax = Math.max(xMax, xl.get(i)); xMin = Math.min(xMin, xl.get(i));
            yMax = Math.max(yMax, yl.get(i)); yMin = Math.min(yMin, yl.get(i));
        }
        
        String[] answer = new String[(int)(yMax-yMin+1)];
        
        for(int i=0; i<answer.length; i++) {
            answer[i] = "";
            for(long j=xMin; j<=xMax; j++) { answer[i] += "."; }
        }
        
        for(int i=0; i<xl.size(); i++) {
            int x = (int)(xl.get(i)-xMin); int y = (int)(yMax-yl.get(i));
            StringBuilder sb = new StringBuilder(answer[y]);
            
            sb.setCharAt(x, '*');
            answer[y] = sb.toString();
        }
        
        return answer;
    }
    
    public boolean check(double x, double y) {
        if(x==(long)x && y==(long)y) { return true; }
        else { return false; }
    }
}

'Problem Solving > Programmers' 카테고리의 다른 글

[Level 2] 카카오프렌즈 컬러링북  (0) 2022.04.07
[Level 2] 모음 사전  (0) 2022.04.06
[Level 2] 구명보트  (0) 2022.04.06
[Level 2] 주식가격  (0) 2022.04.06
[Level 2] 영어 끝말잇기  (0) 2022.04.06