-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaskifyString.cpp
36 lines (27 loc) · 905 Bytes
/
maskifyString.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
// Usually when you sign up for an account to buy something, your credit card number, phone number or answer
// to a secret question is partially obscured in some way. Since someone could look over your shoulder, you
//don't want that shown on your screen. Hence, the website masks these strings.
// // Your task is to create a function that takes a string, transforms all but the last four characters
// into "#" and returns the new masked string.
// Examples
// maskify("4556364607935616") ➞ "############5616"
// maskify("64607935616") ➞ "#######5616"
// maskify("1") ➞ "1"
// maskify("") ➞ ""
#include<iostream>
using namespace std;
std::string maskify(std::string str) {
if (str.length()>=4)
{
for (int i = 0; i < str.length()-4; i++)
{
str[i] = '#';
}
}
return str;
}
int main()
{
cout<<maskify("12345");
return 0;
}