Ad
  • Custom User Avatar

    Why you need to decrease the "unit" in the loop?

    while( result.length() % unit != 0 ) unit /= 3;

    I suggest replacing "regex_search" with "sregex_iterator":

    	regex reg("1+|0+");
    	int unit = INT_MAX;
    	for (std::sregex_iterator it(text.begin(), text.end(), reg), end; it != end; ++it)
    	{
    		const auto length = (*it)[0].length();
    		if (length < unit)
    			unit = length;
    	}
    
  • Custom User Avatar

    Converting to int makes the * 2 + 1 operations done in integer arithmetics, which probably ends up saving a few cpu cycles.

    Also prevents warnings about losing precision when implicitly converting from double to int.

  • Custom User Avatar

    This solution does not actually pass the tests...
    As mentioned, it should take into account the case where the ball bounces at the exact height of the window.
    It would have been nice if it worked like this.

    And I think that (int)floor() is redundant.

  • Custom User Avatar

    In this test, you should have the char 255 at some point in the input.
    Then 255+1 = 0, and it breaks the loop.

  • Custom User Avatar