Codesignal
<Codesignal> firstDigit
우현짱짱
2020. 4. 5. 18:58
Easy
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'.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string inputString
A string containing at least one digit.
Guaranteed constraints:
3 ≤ inputString.length ≤ 10. -
[output] char
[C] Syntax Tips
// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
char * answer = malloc(strlen(name) + 8);
printf("This prints to the console when you Run Tests");
strcpy(answer, "Hello, ");
strcat(answer, name);
return answer;
}
더보기
Solution
char firstDigit(char *inputString)
{
for(int i=0;i<strlen(inputString);i++)
if(isdigit(inputString[i]))
return inputString[i];
}
728x90