int Algorithm::numUniqueEmails(vector<string>& emails)
{
map<string, bool> mapEmail;
vector<string>::iterator itorEmail = emails.begin();
for (; itorEmail != emails.end(); itorEmail++)
{
string strEmail = *itorEmail;
int nStr = strEmail.length();
char sEmail[100] = "";
bool bSkip = false;
bool bHasAt = false;
int iName = 0;
for (int iStr = 0; iStr != nStr; iStr++)
{
char chS = strEmail[iStr];
if (chS == '@' && !bHasAt)
{
bSkip = false;
bHasAt = true;
}
else if (chS == '+')
{
bSkip = true;
continue;
}
else if (chS == '.' && !bHasAt)
{
continue;
}
else if (bSkip)
{
continue;
}
sEmail[iName++] = chS;
}
string strName = sEmail;
mapEmail.insert(make_pair(strName, true));
}
return mapEmail.size();
}