[BOJ-Code] 7568 - 덩치

Posted by DHniyeo Blog on March 10, 2024

문제 링크

💡 브루트포스 알고리즘/구현

Memory 1112KB Time 0ms Code Length 500B

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
31
#include <stdio.h>
#include <queue>
using namespace std;
int n, m;

int main()
{
	int n;
	pair<int,int> man[50];
	int result[50];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf(" %d %d", &man[i].first, &man[i].second);
	}

	for (int i = 0; i < n; i++) {
		int cnt = 0;
		for (int j = 0; j < n; j++) {
			if (man[i].first < man[j].first && man[i].second < man[j].second) {
				cnt++;
			}
		}
		cnt++;
		result[i] = cnt;
	}

	for (int i = 0; i < n; i ++ ) {
		printf("%d ", result[i]);
	}

}

이 코드는 입력으로 받은 사람들의 키와 몸무게를 비교하여 각 사람이 몇 명보다 큰지를 계산하는 프로그램이다. 먼저 입력으로 받은 사람들의 키와 몸무게를 pair로 저장한 후, 각 사람에 대해 다른 사람들과 비교하여 큰 경우를 세어 결과를 저장한다. 이후 결과를 출력한다.