Ad
  • Default User Avatar

    This code can definitely improve. It can invoke undefined behaviour on systems with a signed char (on x86_64 for example) if string contains "negative" characters (say the input contains some UTF-8 codepoints). This is because tolower is actually supposed take an unsigned char cast to int, or alternatively EOF, with all other values invoking UB. Plus, you probably don't want to use tolower anyways as it is locale-dependant. Edit: And also, inconsistent formatting, please move all your pointer asterisks * to one direction! Remember that the optimal type for sizes, counting, etc in C is size_t from <stddef.h>.

  • Custom User Avatar

    tolower() is defined in ctype.h header file, shouldn't you include it?

  • Custom User Avatar

    I agree with this.
    But wouldn't it be nicer to get rid of tolower? One can use a switch and "hardcode" both ascii values for x and o respectively. Also we could omit the char *p since we can iterate on str, but that's very likely optimized away by the compiler anyway.

  • Default User Avatar

    use a single var to keep the count and then its perfect

  • Custom User Avatar

    Please include more information if this is still an issue after 1 year.

  • Custom User Avatar

    You have typo in your code and it did not work, It should have been '\0' instead of '\n'.

    So the following fix works.

    string to_postfix(const string& infix) {
      int pos = find(infix.begin(), infix.end(), '\0') - infix.begin();
      return to_postfix_NEW(infix.substr(0, pos)) + infix.substr(pos, infix.size() - pos);
    }
    
  • Custom User Avatar
    simpleAndNestedLoops(SolutionTests)
     Your interpreter should jump to the command straight *after* the matching "[" on the iteration where it hits the "]" and *not* the matching "[" itself expected:<10000
    01000
    00[1]00
    00000
    00000
    00...> but was:<10000
    01000
    00[0]00
    00000
    00000
    00...>
    

    I think the spec for ']' differs from the one of this test case. My solution is in Java.

  • Custom User Avatar

    Line if (token.length()>1) mPlus.remove(mPlus.size()-1);
    is redundant and can be removed.

  • Default User Avatar

    Got the same problem when submitting python code.

  • Custom User Avatar

    How do I handle "Unknown Error"? Help please!

  • Custom User Avatar

    Add Rust too, please!