//=============================================================================

#include <iostream>
#include <map>
#include <string>
using namespace std;

//-----------------------------------------------------------------------------

int main()
{
   cout << "Aufg_10_05_Telefonbuch_1\n\n";

   map<string, string> book
   {
      { "Detlef", "0123 / 12 21 1" },
      { "Edgar", "0111 / 11 11 1" },
      { "Edmund", "0222 / 33 22 11" },
      { "Dietmar", "0321 / 888 222 99" },
      { "Karl", "0111 / 11 22 33" },
      { "Bernd", "0555 / 55 55 55" }
   };

   for (string s;;)
   {
      cout << "\nEingabe: ";
      getline(cin, s);
      if (s.empty()) continue;
      cout << '\n';

      if (s == "end")
      {
         cout << "Programmende\n";
         break;
      }

      if (s == "list")
      {
         cout << book.size() << " Eintraege:\n";
         map<string, string>::const_iterator it = cbegin(book);
         map<string, string>::const_iterator eit = cend(book);
         for (; it != eit; ++it)
         {
            cout << "- " << it->first << " => " << it->second << '\n';
         }
         continue;
      }

      map<string, string>::const_iterator fit = book.find(s);
      if (fit == cend(book))
      {
         cout << "Name \"" << s << "\" ist nicht im Telefonbuch vorhanden.\n";
         continue;
      }

      cout << fit->first << " => " << fit->second << '\n';
   }
}
