-
Notifications
You must be signed in to change notification settings - Fork 3
/
831.cpp
32 lines (32 loc) · 1013 Bytes
/
831.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
class Solution {
public:
string maskPII(string s) {
if (s.find('@') != string::npos) {
// email
int index = s.find('@');
int n = s.size();
for (int i = 0; i < n; ++i) {
s[i] = tolower(s[i]);
}
string name = s.substr(0, index);
string domain = s.substr(index + 1);
return name.substr(0, 1) + "*****" + name.substr(name.size() - 1) + "@" + domain;
}
else {
string clear;
for (auto& c : s) {
if (isdigit(c)) clear.push_back(c);
}
reverse(clear.begin(), clear.end());
string res;
int n = clear.size();
res += clear.substr(0, 4);
res += "-***-***";
if (n == 11) res += "-*+";
else if (n == 12) res += "-**+";
else if (n == 13) res += "-***+";
reverse(res.begin(), res.end());
return res;
}
}
};