From cfa0f8739573f11962194265477e5afc862a5bae Mon Sep 17 00:00:00 2001 From: rl544 <111494264+rl544@users.noreply.github.com> Date: Fri, 16 Dec 2022 00:36:53 +0900 Subject: [PATCH] =?UTF-8?q?uploaded=20at=202022.=2012.=2016.=20=EC=98=A4?= =?UTF-8?q?=EC=A0=84=2012:36:52?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- programmers/체육복/solution.java | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 programmers/체육복/solution.java diff --git a/programmers/체육복/solution.java b/programmers/체육복/solution.java new file mode 100644 index 0000000..83c8cb1 --- /dev/null +++ b/programmers/체육복/solution.java @@ -0,0 +1,66 @@ +// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/42862# + +import java.util.HashMap; +import java.util.ArrayList; +class Solution { + private static void rl(ArrayList list, HashMap ha, int n){ + for(int i : list){ + int c = ha.get(i); + if(c == 0) { + System.out.println("00"+i+" : "+c); + if (i < n && ha.get(i+1) == 2){ + ha.put(i+1,1); + System.out.println(i+1+" : "+1); + ha.put(i, 1); + } else if(i > 1 && ha.get(i-1) == 2) { + ha.put(i-1,1); + System.out.println(i-1+" : "+1); + ha.put(i, 1); + } + } + } + } + public int solution(int n, int[] lost, int[] reserve) { + int answer = 0; + HashMap ha = new HashMap<>(); + ArrayList laa = new ArrayList<>(); + ArrayList lab = new ArrayList<>(); + for(int i = 1; i <= n; i++){ + ha.put(i,1); + System.out.println(i); + } + for(int i : lost){ + ha.put(i, ha.get(i)-1); + } + for(int i : reserve){ + int c = ha.get(i); + ha.put(i, c+1); + } + for(int i : lost){ + System.out.println("TestOn"); + if(ha.get(i) == 1) { + System.out.println("breaked by 1 and i = "+i); + continue; + } + int count = 0; + for(int j : reserve){ + if(Math.abs(i-j)==1) count += ha.get(j); + } + System.out.println(i+" cou"+count); + if(count >= 4) { + lab.add(i); + } else if(count >= 1){ + laa.add(i); + } + } + System.out.println(lab); + System.out.println(laa); + rl(laa, ha, n); + rl(lab, ha, n); + for(int i = 1; i <= n; i++){ + answer += (ha.get(i) > 0) ? 0 : 1; + System.out.println(i+" : "+ha.get(i)); + } + return n - answer; + } +} \ No newline at end of file