Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- struct Date {
- int day;
- int month;
- int year;
- };
- int compare (Date date1, Date date2) {
- if (date1.year != date2.year) {
- if (date1.year > date2.year) {
- return 1;
- }
- if (date1.year < date2.year) {
- return -1;
- }
- }
- else if (date1.month != date2.month) {
- if (date1.month > date2.month) {
- return 1;
- }
- if (date1.month < date2.month) {
- return -1;
- }
- }
- else if (date1.day != date2.day) {
- if (date1.day > date2.day) {
- return 1;
- }
- if (date1.day < date2.day) {
- return -1;
- }
- }
- else {
- return 0;
- }
- }
- void mySwap (Date& d1, Date& d2) {
- Date buf;
- buf.day = d2.day;
- buf.month = d2.month;
- buf.year = d2.year;
- d2.day = d1.day;
- d2.month = d1.month;
- d2.year = d1.year;
- d1.day = buf.day;
- d1.month = buf.month;
- d1.year = buf.year;
- }
- void heapify(Date* a, Date* b, int i, int n) {
- int largest = i;
- int left = 2 * i + 1;
- int right = 2 * i + 2;
- if((left < n) && (compare(a[left], a[largest]) == 1)) {
- largest = left;
- }
- if((right < n) && (compare(a[right], a[largest]) == 1)) {
- largest = right;
- }
- if(largest != i){
- mySwap(a[i], a[largest]);
- mySwap(b[i], b[largest]);
- heapify(a, b, largest, n);
- }
- }
- void buildHeap(Date* a, Date* b, int n){
- for(int i = n / 2 -1; i >= 0; i--) {
- heapify(a, b, i, n);
- }
- }
- void heapSort(Date* a, Date* b, int n) {
- buildHeap(a, b, n);
- for(int i = n - 1; i >= 1; i--) {
- mySwap(a[0], a[i]);
- mySwap(b[0], b[i]);
- heapify(a, b, 0, i);
- }
- }
- bool isAdult(Date b, Date d) {
- if (d.year - b.year > 18) {
- return true;
- }
- else if (d.year - b.year == 18) {
- if (d.month > b.month) {
- return true;
- }
- else if (d.month == b.month) {
- if (d.day > b.day) {
- return true;
- }
- else
- return false;
- }
- else
- return false;
- }
- else
- return false;
- }
- int maxAge(Date b, Date d) {
- int result = d.year - b.year;
- if (d.month < b.month) {
- result--;
- }
- if (d.month == b.month) {
- if (d.day < b.day) {
- result--;
- }
- }
- return result;
- }
- int main() {
- int n;
- int cnt = 0;
- std::cin >> n;
- Date* left = new Date[n];
- Date* right = new Date[n];
- for (int i = 0; i < n; i++) {
- Date birth,death;
- std::cin >> birth.day >> birth.month >> birth.year;
- std::cin >> death.day >> death.month >> death.year;
- if (isAdult(birth, death)) {
- Date buf;
- buf = birth;
- buf.year += 18;
- left[cnt] = buf;
- if (maxAge(birth, death) < 80) {
- right[cnt] = death;
- }
- else {
- buf = birth;
- buf.year += 80;
- buf.day--;
- right[cnt] = buf;
- }
- cnt++;
- }
- }
- heapSort(left, right, cnt);
- for (int i = 0; i < cnt; i++) {
- std::cout << left[i].day <<' '<<left[i].month<<' '<< left[i].year<<' '
- <<right[i].day<<' '<< right[i].month <<' '<< right[i].year<<std::endl;
- }
- delete[] left;
- delete[] right;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement