본문 바로가기

Beakjoon/brute force

[백준] 7568번 덩치 (C++) - brute force

문제

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

 

7568번: 덩치

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

www.acmicpc.net

코드

#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main(){
  int n, rank;
  vector<pair<int, int>> v;

  cin >> n;

  for(int i=0; i<n; i++){
    int x, y;
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }

  for(int i=0; i<n; i++){
    rank = 1;
    for(int j=0; j<n; j++){
      if(v[i].first <v[j].first && v[i].second < v[j].second){
        rank+=1;
      }
    }
    cout << rank << ' ';
  }

  return 0;
}

정리

pair는 두 가지 데이터를 같이 묶어서 저장할 수 있는 클래스이다.

pair는 <utility> 헤더에 존재한다

pair<type1, type2> p 다음과 같이 선언할 수 있다.

p.first는 p의 첫번째 인자를 p.second는 p의 두번째 인자를 반환해 준다.

make_pair(x, y) : 변수 x와 y가 들어간 pair를 만들어준다.

참조

https://blockdmask.tistory.com/64