#include <iostream>
  using std::cerr;
  using std::cout;
  using std::endl;
  using std::cin;
#include <list>
  using std::list;
#include <vector>
  using std::vector;
#include <string>
  using std::string;
#include <algorithm>
  using std::sort;
  using std::for_each;

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

static Date silvester(31, 12);

/* -- 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);
}

/* -- comparison function for person pointers (first name) -- */
bool PersFirstLess(const Person *lhs, const Person *rhs) {
   return (lhs->firstName() <= rhs->firstName());
}

/* -- comparison functor for person pointers (last name) -- */
struct PersNameLess {
  bool operator()(const Person *lhs, const Person *rhs) {
   return (lhs->lastName() <= rhs->lastName());
  }
};

/* -- functor for print out person data and release memory -- */
struct ProcessPers {
  void operator()(const Person *p) {
    cout << p->lastName() << ' ' << p->firstName() << ' ' <<
            p->birthday() << ", Alter: " << silvester - p->birthday() <<
            " Tage" << endl;
    delete p;
  }
};

int main() {
  string nbuf;
  string fbuf;
  int y, m, d;
  list<Person*> plist;
  vector<Person*> pvector;

  /* -- read persons from stdin and put them in container -- */
  while ( getrecord(nbuf, fbuf, y, m, d) ) {
    plist.push_back(new Person(nbuf, fbuf, d, m, y));
    pvector.push_back(new Person(nbuf, fbuf, d, m, y));
  }

  /* -- print out sorted list and delete container elements -- */
  plist.sort(PersNameLess());
  for_each(plist.begin(), plist.end(), ProcessPers());

  /* -- print out sorted vector and delete container elements -- */
  sort(pvector.begin(), pvector.end(), PersFirstLess);
  for_each(pvector.begin(), pvector.end(), ProcessPers());
  return 0;
}