algorithm'''problem solve
[백준]7568-덩치(설명X)
JunHwa Park
2019. 8. 16. 17:07
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 | #include <iostream> using namespace std; class Person { private: int height, weight, rank; public: Person() { this->height = 0; this->weight = 0; this->rank = 1; } void setInfo(int weight, int height) { this->weight = weight; this->height = height; } static void compare(Person &person1, Person &person2) { if (person1.weight > person2.weight && person1.height > person2.height) person2.rank++; else if (person1.weight < person2.weight && person1.height < person2.height) person1.rank++; } int getRank() { return this->rank; } }; int main() { int input; cin >> input; Person* person = new Person[input]; for (int i = 0; i < input; i++) { int height, weight; cin >> weight >> height; person[i].setInfo(weight, height); for (int j = 0; j < i; j++) Person::compare(person[i], person[j]); } for (int i = 0; i < input; i++) cout << person[i].getRank() << " "; cout << endl; } | cs |