[acmicpc] 백준 7568 덩치 C언어 정답 코드
2020. 4. 12. 02:46ㆍ알고리즘/acmicpc 코드
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <stdio.h>
#include <stdlib.h>
typedef struct _Person
{
public:
unsigned int nWeight;
unsigned int nHeight;
unsigned int nRank;
bool operator<(struct _Person& other) const;
} Person;
typedef Person *People;
bool Person::operator<(Person& other) const
{
if(this->nWeight < other.nWeight)
{
if(this->nHeight < other.nHeight) return true;
}
return false;
}
int main(void)
{
unsigned int nCount;
scanf("%u", &nCount);
People people = (People) malloc(sizeof(Person) * nCount);
for(unsigned int i = 0; i < nCount; i++)
{
scanf("%u %u", &((people+i)->nWeight), &((people+i)->nHeight));
}
for(unsigned int i = 0; i < nCount; i++)
{
unsigned int nRank = 1;
for(unsigned int j = 0; j < nCount; j++)
{
if(i == j) continue;
if(*(people+i) < *(people+j))
{
nRank++;
}
}
(people+i)->nRank = nRank;
}
for(unsigned int i = 0; i < nCount; i++)
{
printf("%u ", (people+i)->nRank);
}
free(people);
return 0;
}
|
cs |
복잡하게 생각하면 삼천포에 빠질 수 있는 문제인 것 같다.
본인은 문제를 안 읽고 풀기 시작해서 바보짓을 여러 번 했다.
'자신보다 더 큰 덩치의 사람이 k명이라면 그 사람의 덩치 등수는 k+1이 된다.'
위의 조건만 잘읽었으면 문제가 쉽게 풀린다...
'알고리즘 > acmicpc 코드' 카테고리의 다른 글
[acmicpc] 10814 나이순 정렬 정답 코드 (0) | 2020.04.13 |
---|---|
[acmicpc] 11650 좌표 정렬하기 정답 코드 (0) | 2020.04.12 |
[acmicpc] 백준 1018 체스판 다시 칠하기 정답 코드 (0) | 2020.04.12 |
[acmicpc] 백준 2446번: 별 찍기 - 9 (피라미드 출력하기) (0) | 2020.04.09 |
[어셈블리어] 백준 2557번 Hello World 런타임 오류 해결법 (0) | 2020.01.29 |