forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0929.cpp
41 lines (40 loc) · 1.11 KB
/
0929.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int numUniqueEmails(vector<string>& emails)
{
unordered_set<string> result;
for (auto& email : emails)
{
auto at_pos = email.find('@');
auto plus_pos = email.find('+');
if (plus_pos < at_pos)
{
auto len = at_pos - plus_pos;
email.erase(plus_pos, len);
at_pos -= len;
}
auto dot_pos = email.find('.');
while (dot_pos < at_pos)
{
email.erase(dot_pos, 1);
at_pos--;
dot_pos = email.find('.');
}
result.insert(email);
}
return result.size();
}
};
int main()
{
vector<string> emails = {"test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"};
cout << Solution().numUniqueEmails(emails);
return 0;
}