Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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
more
Archives
Today
Total
관리 메뉴

잉여의 IT

[백준 7568번: 덩치] 자바 문제풀이 본문

백준 풀이

[백준 7568번: 덩치] 자바 문제풀이

프로잉여 2022. 7. 19. 23:36

브루트포스 알고리즘 문제이다.

각 사람끼리 키와 몸무게를 한번씩 다 돌아가면서 매칭하여 비교하고 자신보다 덩치가 큰 사람의 수를 세는 간단한 문제이다.

import java.util.Scanner;

public class Main{
	
	void Grade(int N,int[][] arr) {
		int grade[]= new int[N];
		int x,y,p,q;
		for(int i=0; i<N; i++)
			grade[i]=1;
		
		for(int i=0; i<N; i++) {
			x=arr[i][0];
			y=arr[i][1];
			for(int j=0; j<N; j++) {
				if(i!=j) {
					p=arr[j][0];
					q=arr[j][1];
					if(x<p && y<q)
						grade[i]++;
				}
			}
		}
		for(int i=0; i<N; i++)
			System.out.print(grade[i]+" ");
	}
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Main Main = new Main();
		
		int N = scanner.nextInt();
		int[][] arr=new int[N][2];
		for(int i=0; i<N; i++) {
			arr[i][0]=scanner.nextInt();
			arr[i][1]=scanner.nextInt();
		}
		
		Main.Grade(N,arr);

	
		scanner.close();
	}

}
Comments