108th LeetCode Weekly Contest Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign.
For example, in alice@leetcode.com
, alice
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的更多相关文章
- 【leetcode】929. Unique Email Addresses
题目如下: Every email consists of a local name and a domain name, separated by the @ sign. For example, ...
- 【LeetCode】929. Unique Email Addresses 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set + 字符串操作 参考资料 日期 题目地址:h ...
- LeetCode题解之Unique Email Addresses
1.题目描述 2.问题分析 将字符串中的 ‘.’ 去掉,将 ‘+’后面直到‘@’的字符串去掉,然后利用set的特性. 3.代码 int numUniqueEmails(vector<string ...
- 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 ...
- 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, ...
- [leetcode] 929. Unique Email Addresses (easy)
统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...
- 929. Unique Email Addresses
929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...
- LeetCode Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
随机推荐
- c语言实践 用1角 2角 5角 凑成10元钱的方法
/* 用1角,2角,5角凑出10元钱,有几种办法. 也就是0.1a+0.2b+0.3c=10,化简一下就是 a=100-2b-3c 因为a的范围是0到100,所以弄一个循环 把a的值从0尝试到100, ...
- Entity Framework 6.0 Tutorials(7):DbSet.AddRange & DbSet.RemoveRange
DbSet.AddRange & DbSet.RemoveRange: DbSet in EF 6 has introduced new methods AddRange & Remo ...
- Robot Framework - 常用断言讲解
RobotFramework带有丰富的系统关键,使用时无需导入,直接使用,为写自动化用例带来了极大的方便:不能停留在知道或者是会得程度,只有熟练使用各关键字,才能提升自动化用例的写作效率. 下面将逐个 ...
- TensorFlow中文手册
注意:本文只为读书笔记. 第一章 起步 - 起步 - [介绍](SOURCE/get_started/introduction.md) - [下载及安装](SOURCE/get_started/os_ ...
- 问渠那得清如许?为有源头活水来。——java面向对象的思想
20169205 2016-2017-2 <移动平台应用开发实践>第2周学习总结 教材学习内容总结 本次作业要求的部分主要是Java高级语言实现面向对象编程的基本方法,其中所介绍的面向对象 ...
- eclipse启动了tomcat,但是浏览器打不开欢迎页
tomcat在eclipse中启动成功,主页却打不开 症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他 ...
- Android Butterknife框架 注解攻略
一.原理. 最近发现一个很好用的开源框架,蛮不错的,可以简化你的代码,是关于注解的.不多说直接进入使用步骤讲解. 二.步骤. 1.准备阶段,先到官网( http://jakewharton.githu ...
- 使用 Windows Phone 8 文件和 URI 关联的自动启动应用
更详细,猛撸这里:http://msdn.microsoft.com/zh-cn/library/windowsphone/develop/jj206987(v=vs.105).aspx 在WMApp ...
- angular Docheck
import { Component, OnInit, Input, OnChanges, SimpleChanges, DoCheck } from '@angular/core'; @Compon ...
- 如何优雅地使用win10的Linux子系统
转自: http://blog.csdn.net/u010053050/article/details/52388663 http://www.rehack.cn/techshare/devtools ...