#include <iostream>                // OR:   #include <iostream>
  using std::cerr;                 //       #include <list>
  using std::cout;                 //       using namespace std;
  using std::endl;
  using std::cin;
#include <list>
  using std::list;

#include "Person14.h"
#include "Date14.h"

/* -- read on input record and return success/error -- */

bool getrecord(string& nbuf, string& fbuf, int& y, int& m, int& d)
{
  char sep;
  return (cin >> nbuf >> fbuf >> y >> sep >> m >> sep >> d);
}

int main() {
  string nbuf;
  string fbuf;
  int y, m, d;
  list<Person *> persons;
  Person* p;
  Date silvester(31, 12);
  list<Person *>::iterator it;

  /* -- read persons from stdin -- */
  while ( getrecord(nbuf, fbuf, y, m, d) ) {
    /* -- construct new person record -- */
    p = new Person(nbuf, fbuf, d, m, y);

    /* -- add to list (and sort them already at insertion time) -- */
    for ( it = persons.begin(); it != persons.end(); ++it) {
      if (*p <= **it) break;
    }
    persons.insert(it, p);
  }

  /* -- print out sorted list and delete list -- */
  for ( it = persons.begin(); it != persons.end(); ++it) {
    p = *it;
    cout << p->lastName() << ' ' << p->firstName() << ' ' <<
            p->birthday() << ", Alter: " << silvester - p->birthday() <<
            " Tage" << endl;
    delete p;
  }
  return 0;
}