본문 바로가기
백준/C++

백준 7568번 : 덩치 [C++]

by 대니스 2022. 8. 9.

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

 

7568번: 덩치

우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. 두 사람 A 와 B의 덩

www.acmicpc.net

소스 코드 :

#define _SRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
using namespace std;

typedef struct Person
{
	int height;
	int weight;
	int score;
	int grade;
};

int main()
{
	int person;
	Person p[50];

	cin >> person;
	for (int i = 0;i < person;i++)
	{
		p[i].score = 0;
		cin >> p[i].weight >> p[i].height;
		p[i].grade = 1;
	}

	for(int i=0;i<person;i++)
		for (int j = 0;j < person;j++)
		{
			if (i == j)
				continue;
			
			if (p[i].weight < p[j].weight && p[i].height < p[j].height)
				p[i].grade++;
		
		}

	for (int i = 0;i < person;i++)
		cout << p[i].grade << ' ';

}

마무리 : 본인은 글을 잘 못 읽어서 계속 틀리다가 맞춘 문제이다. 무게와 키 둘 다 커야 더 덩치가 큰 것인데 이것을 따로 생각해서 틀리게 된 것이다.