알고리즘/codefights

47>isMAC48Address

Diademata 2017. 11. 4. 00:24
반응형

Given a string, return its encoding defined as follows:


First, the string is divided into the least possible number of disjoint substrings consisting of identical characters

for example, "aabbbc" is divided into ["aa", "bbb", "c"]

Next, each substring with length greater than one is replaced with a concatenation of its length and the repeating character

for example, substring "bbb" is replaced by "3b"

Finally, all the new strings are concatenated together in the same order and a new string is returned.

Example


For s = "aabbbc", the output should be

lineEncoding(s) = "2a3bc".


code>>


bool isMAC48Address(std::string inputString) {

std::regex reg("^[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}");

std::smatch m;

return std::regex_match(inputString, m, reg);

}

반응형