929. Unique Email Addresses
Easy

22766FavoriteShare

Every email consists of a local name and a domain name, separated by the @ sign.

For example, in alice@leetcode.comalice is the local name, and leetcode.com is the domain name.

Besides lowercase letters, these emails may contain '.'s or '+'s.

If you add periods ('.') between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name.  For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address.  (Note that this rule does not apply for domain names.)

If you add a plus ('+') in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered, for example m.y+name@email.com will be forwarded to my@email.com.  (Again, this rule does not apply for domain names.)

It is possible to use both of these rules at the same time.

Given a list of emails, we send one email to each address in the list.  How many different addresses actually receive mails?

Example 1:

Input: ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]
Output: 2
Explanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails

Note:

  • 1 <= emails[i].length <= 100
  • 1 <= emails.length <= 100
  • Each emails[i] contains exactly one '@' character.
Accepted
46,564
Submissions
58,349
class Solution {
public: int numUniqueEmails(vector<string>& emails) {
map<string,int> m1;
int point,add,at;
for(auto &astr:emails){
at=findc(astr,'@',,astr.length()-);
if(at!=-){
while( (add=findc(astr,'+',,at)) !=-){
astr.erase(add,at-add);
at-=(at-add);
}
}
while( (point=findc(astr,'.',,at)) != -){
astr.erase(point,);
at-=;
}
m1[astr]++;
}
return m1.size();
}
int findc(string str,char c,int start,int end){
for(int i=start;i<=end;i++){
if(str[i]==c) return i;
}
return -;
} };

最新文章

  1. SQL Server中的高可用性(2)----文件与文件组
  2. javaweb写的在线聊天应用
  3. JSoup笔记
  4. MySQL导入.sql文件及常用命令
  5. VPN推荐
  6. Django1.9开发博客(12)- i18n国际化
  7. hdu 5821 (贪心排序) Ball
  8. CSS 兼容 总结
  9. cocos2dx中的动作
  10. PostgreSQL的 initdb 源代码分析之二
  11. MySQL之删_delete-truncate
  12. Git 安装及用法 github 代码发布 gitlab私有仓库的搭建
  13. Django 设置media static
  14. LeetCode(5):最长回文子串
  15. python之常用字符串用法
  16. array_map,array_filter,array_walk区别
  17. Linux内核分析作业 NO.2
  18. ==、is
  19. [日常] 编写HTTP接口文档
  20. 几个不同版本的framework改进

热门文章

  1. RandomAccessFile出现中文乱码问题
  2. $(document).ready和window.onload的区别
  3. jmeter发起form-data格式
  4. fiddler抓包——IOS
  5. ROS与C++
  6. 【java】java基本用法记录
  7. 《剑指offer》二叉树的深度
  8. PADS Layout VX.2.3 出Gerber文件时遇到一个奇怪的现象
  9. NAT穿透解决
  10. [原创]基于Zynq SDIO WIFI 2.4G/5G SotfAP STA