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. opennebula 模板参数说明

    两种模板配置方式一.光驱引导启动需要配置:disk1:磁盘类型:cdrom      驱动类型:file      磁盘标记:hd      是否只读:yesDisk2:磁盘类型:DATABLOCK驱 ...

  2. 20-取石子动态规则(hdu2516 斐波那契博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=2516 取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  3. c# 获取客户端ip、mac、机器名、操作系统、浏览器信息

    d using System; using System.Collections.Generic; using System.Linq; using System.Web; using System. ...

  4. CSS文本溢出处理

    1.超出层的高度和宽度时文本自动隐藏 overflow:hidden;text-overflow:ellipsis; 2.超出层的宽度时隐藏溢出的文本以...表示,Firefox不兼容,只隐藏溢出的文 ...

  5. Solidity oraclize 常用数据源

    1. 股票数据: https://blog.quandl.com/api-for-stock-data iextrading.com www.nowapi.com 中文 2. 外汇数据: https: ...

  6. Luogu 1379 八数码难题

    吐槽:此题就是一点一点卡过去的 警告: 1.千万不能用dfs搜这种东西(dfs需要遍历所有状态才能找到最优解), 分分钟爆炸 2.写结构体的时候要综合判断&的加和不加 Code: // luo ...

  7. [Lua快速了解一下]Lua的控制语句

    -Lua中没有++或者--的骚操作 -while loop sum = num = do sum = sum + num num = num + end print("sum =" ...

  8. Alpha项目复审

    队名 优点 缺点 排名 拉登是我罩的 1.最底层.从无到有实现的软硬件结合的俄罗斯方块游戏. 2.从画电路原理图.PCB电路板设计.接线.操作系统(没用到操作系统).驱动程序.应用程序开发,串口通信. ...

  9. Log--检查各数据库日志的使用情况

    -- Recovery model, log reuse wait description, log file size,-- log usage size and compatibility lev ...

  10. ComicEnhancerPro 系列教程十七:二值化图像去毛刺

    作者:马健邮箱:stronghorse_mj@hotmail.com 主页:http://www.comicer.com/stronghorse/ 发布:2017.07.23 教程十七:二值化图像去毛 ...