#include <bits/stdc++.h> using namespace std; struct Person { int age; int grade; Person() {} Person(int age, int grade) { this->age = age; this->grade = grade; } void output(); void add(Person a) { age += a.age; grade += a.grade; } }li[101]; void Person::output() { printf("age: %d grade: %d\n", age, grade); } Person add(Person p1, Person p2) { Person res; res.age = p1.age + p2.age; res.grade = p1.grade + p2.grade; return res; } Person a; bool cmp(Person a,Person b){ if(a.age==b.age){ return a.grade > b.grade; } return a.age<b.age; } int main() { a.age = 10; a.grade = 100; printf("%d %d\n", a.grade, a.age); Person* p = new Person(); p->age = 20; (*p).age = 20; p->grade = 30; printf("%d %d\n", p->age, (*p).grade); Person* p2 = new Person(1000, 10000); printf("%d %d\n", p2->age, p2->grade); p2->add(*p); p2->output(); Person p3 = add(*p2, *p2); p3.output(); int n; scanf("%d",&n); for (int i = 1;i<=n;i++){ scanf("%d%d", &li[i].age, &li[i].grade); } sort(li + 1, li + 1 + n,cmp); for (int i = 1;i<=n;i++){ li[i].output(); } }