본문 바로가기
  • Let's study
PS/백준

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

by 코딩고수이고파 2020. 12. 23.

1. pair 형태로 몸무게랑 키를 vector에 저장, score는 등수 저장 변수로 모두 1로 초기화

2. 벡터의 모든 요소를 하나하나 비교하면서 자신보다 몸무게와 키 둘 다 큰 다른 요소랑 비교할 경우 등수++

3. 등수 출력

#include <iostream>
#include<vector>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<pair<int,int>>v;
	int score[51];

	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		v.push_back(make_pair(a,b));
		score[i] = 1;
	}	

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)
				continue;
			else if (v[i].first < v[j].first && v[i].second < v[j].second)
				score[i]++;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << score[i]<<" ";
	}
	return 0;
}

'PS > 백준' 카테고리의 다른 글

[C++] 백준 2292번: 벌집  (0) 2020.12.26
[C++] 백준 2839번: 설탕 배달  (0) 2020.12.26
[C++] 백준 2231: 분해합  (0) 2020.12.23
[C++] 백준 2798번: 블랙잭  (0) 2020.12.23
[C++] 백준 1316번: 그룹 단어 체커  (0) 2020.12.08

댓글