思路:

将邮件分为两个部分,@之前为本地地址,@之后为域名,需要对本地地址进行判断操作

1.建一个hash表用于存放邮件

2.找到@所在位置 email.find('@')

3.遍历本地名称,对“+”“.”进行处理

4.将处理后的本地name 和域名组合输入到hash 表中

 

代码:

class Solution {
public:
    int numUniqueEmails(vector<string>& emails) {
        unordered_set<string> hash;
        for(auto email :emails)
        {
            int at =email.find('@');//找到@的位置,前面是本地名称,后面是域名
            string name;
            for(auto c :email.substr(0,at)) //对本地名称进行处理
            {
                if(c=='+') break;
                else if(c!='.') name +=c;
            }
            string domain=email.substr(at+1);//截取域名
            hash.insert(name + '@' + domain);
            
        }
        //cout<<hash<<endl;
        return hash.size();
    }
};