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.

没啥好说的,就是个简单的模拟。可以考虑@前后两部分

class Solution {
public:
int numUniqueEmails(vector<string>& emails) {
set<string>Set;
int len = emails.size();
string strlen="";
string x="";
int flag=;
int j=;
int y=;
int Jstr;
for(int i=;i<len;i++){ strlen = emails[i]; flag = ;
j = ;
y = ;
x = "";
Jstr = strlen.length();
while(strlen[j]!='@'){
j++;
} while(y<=j){
if(strlen[y]=='.'){
y++;
}
if(strlen[y]=='+'){
break;
}
x+=strlen[y];
y++;
}
while(j<Jstr){
x+=strlen[j];
j++;
}
//cout<<x<<endl;
Set.insert(x);
}
return Set.size();
}
};

108th LeetCode Weekly Contest Unique Email Addresses的更多相关文章

  1. 【leetcode】929. Unique Email Addresses

    题目如下: Every email consists of a local name and a domain name, separated by the @ sign. For example, ...

  2. 【LeetCode】929. Unique Email Addresses 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set + 字符串操作 参考资料 日期 题目地址:h ...

  3. LeetCode题解之Unique Email Addresses

    1.题目描述 2.问题分析 将字符串中的 ‘.’ 去掉,将 ‘+’后面直到‘@’的字符串去掉,然后利用set的特性. 3.代码 int numUniqueEmails(vector<string ...

  4. 108th LeetCode Weekly Contest Minimum Falling Path Sum

    Given a square array of integers A, we want the minimum sum of a falling path through A. A falling p ...

  5. 108th LeetCode Weekly Contest Binary Subarrays With Sum

    In an array A of 0s and 1s, how many non-empty subarrays have sum S? Example 1: Input: A = [1,0,1,0, ...

  6. [leetcode] 929. Unique Email Addresses (easy)

    统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...

  7. 929. Unique Email Addresses

    929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...

  8. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  9. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

随机推荐

  1. 238. Product of Array Except Self 由非己元素形成的数组

    [抄题]: Given an array of n integers where n > 1, nums, return an array output such that output[i]  ...

  2. 如何学习MySQL

    转自高手的帖子 1.坚持阅读官方手册,看MySQL书籍作用不会特别大:(挑选跟工作相关的内容优先阅读,例如InnoDB存储引擎,MySQL复制,查询优化) 2.阅读官方手册,同时对阅读的内容做对应的测 ...

  3. 图解KMP算法

  4. Mybaties核心配置文件

    <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC &q ...

  5. Python基础入门-列表解析式

    今天我们使用Python中的列表解析式来实现一些简单功能.好了关于列表解析式是什么?我的理解是它可以根据已有列表,高效创建新列表的方式.列表解析是Python迭代机制的一种应用,它常用于实现创建新的列 ...

  6. SQL Server 2012自动备份

    SQL 2012和2008一样,都可以做维护计划,来对数据库进行自动的备份. 现在做这样一个数据库维护的计划,每天0点对数据库进行差异备份,每周日0点对数据库进行完全备份,并且每天晚上10点删除一次过 ...

  7. webrequest、httpwebrequest、webclient、HttpClient 四个类的区别

    一.在 framework 开发环境下: webrequest.httpwebreques  都是基于Windows Api 进行包装, webclient 是基于webrequest 进行包装:(经 ...

  8. React + Python 七月小说网 启程(一)

    一.为啥要做这个网站 很久没有写技术相关的博客了,最近几个月忙飞,各种工作,技术根本学不完,很难受. 趁着春节期间,终于有空闲时间做自己爱做的事情了,美滋滋. 热爱技术,热爱小说,于是诞生了个这么玩意 ...

  9. PHP删除目录

    function delDir($directory) { if(file_exists($directory)) { $dir_handle = @opendir($directory); if($ ...

  10. linux 改变系统时间

    date  查看系统时间 date -s 04/05/16  日期设置成2016年4月5日 date -s 15:03:32  日期设置成2016年4月5日15:03:32 上述两步可以直接写成这样一 ...