![[백준 / BOJ] 7568번 덩치 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FDOrkz%2FbtrJsvO2lhK%2FUB2XRs0aT9rTgFkwRHNNe1%2Fimg.png)
[백준 / BOJ] 7568번 덩치 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 4. 12. 22:47
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/7568
7568번: 덩치
우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. 두 사람 A 와 B의 덩
www.acmicpc.net
문제

문제 풀이
C++ 상세 풀이
C++ 풀이 펼쳐보기
pair를 이용하면 더욱 쉽게 해결할 수 있는 문제다.
for (int i = 0; i < N; ++i)
cin >> arr[i].first >> arr[i].second;
for (int i = 0; i < N; ++i) {
cnt = 1;
for (int j = 0; j < N; j++)
if (arr[i].first < arr[j].first && arr[i].second < arr[j].second)
cnt++;
cout << cnt << " ";
}
Python 상세 풀이
Python 풀이 펼쳐보기
파이썬은 C++보다 리스트의 삽입이 자유로워 C++의 pair와 비슷하게 구현했다.
for i in range(N):
x, y = map(int, input().split())
arr.append((x, y))
for i in arr:
cnt = 1
for j in arr:
if i[0] < j[0] and i[1] < j[1]:
cnt += 1
print(cnt, end=" ")
C++ 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <utility> | |
using namespace std; | |
int main() { | |
int N; | |
int cnt = 1; | |
pair<int, int> arr[50]; | |
cin >> N; | |
for (int i = 0; i < N; ++i) | |
cin >> arr[i].first >> arr[i].second; | |
for (int i = 0; i < N; ++i) { | |
cnt = 1; | |
for (int j = 0; j < N; j++) | |
if (arr[i].first < arr[j].first && arr[i].second < arr[j].second) | |
cnt++; | |
cout << cnt << " "; | |
} | |
return 0; | |
} |
Python 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
arr = [] | |
for i in range(N): | |
x, y = map(int, input().split()) | |
arr.append((x, y)) | |
for i in arr: | |
cnt = 1 | |
for j in arr: | |
if i[0] < j[0] and i[1] < j[1]: | |
cnt += 1 | |
print(cnt, end=" ") |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 1436번 영화감독 숌 (C++, Python) (0) | 2022.04.13 |
---|---|
[백준 / BOJ] 1018번 체스판 다시 칠하기 (C++, Python) (0) | 2022.04.13 |
[백준 / BOJ] 2231번 분해합 (C++, Python) (0) | 2022.04.11 |
[백준 / BOJ] 2798번 블랙잭 (C++, Python) (0) | 2022.04.11 |
[백준 / BOJ] 11729번 하노이 탑 이동 순서 (C++, Python) (0) | 2022.04.10 |
@Reo :: 코드 아카이브
자기계발 블로그