#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
bool ischar(char ch)
{
if ( (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') )
return true;
return false;
}
int main()
{
vector<string> word;
ifstream fin("word.in");
if ( !fin )
{
cerr << "oops! unable to open file "<< endl;
}
char ch;
while ( fin )
{
string tmp;
ch = fin.get();
if (ischar(ch))
{
while( ischar(ch) )
{
if ( isupper(ch) )
{
ch = tolower(ch);
}
tmp += ch;
ch = fin.get();
}
word.push_back(tmp);
}
}
const long len = word.size();
/*for (int j = 0; j < len; ++j)
cout << word[j] << ';';*/
fin.close();
map<string,int> count;
for(int i = 0; i < len; ++i)
count[word[i]]++;
map<string,int>::iterator iter;
ofstream fout("word.out");
if ( !fout )
{
cerr << "oops! unable to open file "<< endl;
}
fout << len << endl;
for (iter = count.begin(); iter != count.end(); iter++)
fout << iter->first << " " << iter->second << endl;
return 0;
}