본문 바로가기
아기 개발자/백준 문제풀이

[BOJ_JAVA] 백준 7568번 : 덩치 @달깅

by 달깅 2019. 11. 5.

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

 

이 문제 진짜 몇 안되는 한 번에 맞았습니다!!! 가 뜬 문제다 ㅎㅎㅎ..

 

이번엔 제네릭을 사용해서 풀어봤다!

어레이도 편하지만 제네릭에도 익숙해 져야 할 것 같당..!

앞으로는 다양하게 써서 문제를 풀어봐야겠다 하하

 

 


정답코드

 

 

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int num=sc.nextInt();
        int count=0;
        ArrayList<Integer> weight=new ArrayList<Integer>();
        ArrayList<Integer> height=new ArrayList<Integer>();
        ArrayList<Integer> dung=new ArrayList<Integer>();

        for (int i=0; i<num; i++) {
            weight.add(sc.nextInt());
            height.add(sc.nextInt());
        }

        for (int i=0; i<num; i++) {
            int w=weight.get(i);
            int h=height.get(i);
            for (int j=0; j<num; j++) {
                if (w<weight.get(j) && h<height.get(j)) {
                    count++;
                }
            }
            dung.add(count);
            count=0;
        }

        for (int i=0; i<num; i++) {
            System.out.print((dung.get(i)+1)+" ");
        }

    }
}

 

댓글