题目链接:https://leetcode-cn.com/problems/masking-personal-information/
解题思路:硬处理
class Solution {
public:
string maskPII(string S) {
auto index = S.find("@");
std::string ans;
if (index != std::string::npos) {
ans = S[0] + std::string("*****") + S.substr(index - 1);
for (auto &tmp:ans)
if ('A' <= tmp && tmp <= 'Z')
tmp = tmp - 'A' + 'a';
return ans;
}
else {
std::string buffer;
for (auto &tmp : S)
if ('0' <= tmp && tmp <= '9')
buffer += tmp;
std::string ans = "***-***-" + buffer.substr(buffer.size() - 4);
if (buffer.size() == 10)
return ans;
return "+" + string(buffer.size() - 10, '*') + "-" + ans;
}
}
};