fixme's blog

By fixme, 14 years ago, In English
In Manthan 2011 Problem A, I first wrote a C++ code which did not compile, and it took me one minute to figure out why it did not.  I proudly declare that I am a C++ newbie.  The following is the relevant part of the code.

for (int i = 0; i < n - 1; ++i)
{
    case (order[i])
    {
    switch 'R':
        lr[i + 1] = lr[i] + 1;
        break;
    switch '=':
        lr[i + 1] = lr[i];
        break;
    switch 'L':
        lr[i + 1] = 1;
        break;
    }
}
  • Vote: I like it
  • +15
  • Vote: I do not like it

| Write comment?
14 years ago, # |
  Vote: I like it +1 Vote: I do not like it
Fun. Me too :) Have you ever used Basic?
  • 14 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    I used QuickBASIC (a precursor to Visual Basic) a long time ago, but the reason I typed “case” without thinking is probably that I recently use Haskell often.
14 years ago, # |
  Vote: I like it +9 Vote: I do not like it
Took me a couple of seconds. Funny, however.
14 years ago, # |
  Vote: I like it 0 Vote: I do not like it
whats the funny thing? it flew over my head. 
  • 14 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    It is funny to me because the code which had looked perfectly correct turned out to be just obviously wrong once I realized the error in it.  I guess that you noticed the error immediately without having to stare at the code, in which case it is probably not funny at all.