알고리즘/codefights

35>firstDigit

Diademata 2017. 7. 31. 17:24
반응형

Find the leftmost digit that occurs in a given string.


Example


For inputString = "var_1__Int", the output should be

firstDigit(inputString) = '1';

For inputString = "q2q-q", the output should be

firstDigit(inputString) = '2';

For inputString = "0ss", the output should be

firstDigit(inputString) = '0'.


code>>


char firstDigit(std::string inputString) {

std::regex r("[^0-9]");

return regex_replace(inputString, r, "").c_str()[0];

}

반응형