Справочное руководство по C++

B2_3__10.cxx.

#include ‹stream.hxx›

Struct pair {

 char* name;

 int val;

};

Extern int strlen(char*);

Extern int strcpy(char*, char*);

Extern int strcmp(char*, char*);

Const large = 1024;

Static pair vec[large];

Pair* find(char* p).

{

 for (int i=0; vec[i].name; i++).

  if (strcmp(p,vec[i].name)==0) return &vec[i];

 if (i == large) return &vec[large-1];

 return &vec[i];

}

Int& value(char* p).

{

 pair* res = find(p);

 if (res-›name == 0) {

  res-›name = new char[strlen(p)+1];

  strcpy(res-›name,p);

  res-›val = 0;

 }

 return res-›val;

}

Const MAX = 256;

Main ().

{

 char buf [MAX];

 while (cin››buf) value(buf)++;

 for (int i=0; vec[i].name; i++).

  cout ‹‹ vec[i].name ‹‹ ":" ‹‹ vec[i].val ‹‹ "\n";

}