Easy

Define an integer's roundness as the number of trailing zeroes in it.

Given an integer n, check if it's possible to increase n's roundness by swapping some pair of its digits.

Example

  • For n = 902200100, the output should be
    increaseNumberRoundness(n) = true.

    One of the possible ways to increase roundness of n is to swap digit 1 with digit 0 preceding it: roundness of 902201000 is 3, and roundness of n is 2.

    For instance, one may swap the leftmost 0 with 1.

  • For n = 11000, the output should be
    increaseNumberRoundness(n) = false.

    Roundness of n is 3, and there is no way to increase it.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer n

    A positive integer.

    Guaranteed constraints:
    100 ≤ n ≤ 10^9.

  • [output] boolean

    • true if it's possible to increase n's roundness, false otherwise.

[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

bool increaseNumberRoundness(int n)
{
	while(n%10==0)
		n/=10;

	while(n>0)
	{
		if(n%10==0)
			return true;
		n/=10;
	}

	return false;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Candles  (0) 2020.04.13
<Codesignal> Rounders  (0) 2020.04.13
<Codesignal> Apple Boxes  (0) 2020.04.12
<Codesignal> Addition Without Carrying  (0) 2020.04.12
<Codesignal> Lineup  (0) 2020.04.12

+ Recent posts