Easy

Given a string, output its longest prefix which contains only digits.

Example

For inputString = "123aa1", the output should be
longestDigitsPrefix(inputString) = "123".

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] string inputString

    Guaranteed constraints:
    3 ≤ inputString.length ≤ 100.

  • [output] string

[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 *longestDigitsPrefix(char *inputString)
{
	int i=0;

	while(isdigit(inputString[i++]));
	inputString[--i]='\0';

	return inputString;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Bishop and Pawn  (0) 2020.04.05
<Codesignal> digitDegree  (0) 2020.04.05
<Codesignal> Knapsack Light  (0) 2020.04.05
<Codesignal> growingPlant  (0) 2020.04.05
<Codesignal> arrayMaxConsecutiveSum  (0) 2020.04.05

+ Recent posts