fixme's blog

By fixme, 13 years ago, In English

I wrote the following C++ code while I was trying to solve Google Code Jam 2011 Qualification Round Problem C “Candy Splitting” (the code presented here is slightly modified but essentially the same).

int N;
scanf("%d", &N);
vector<int> candies(N);
for (int i = 0; i < N; ++i)
    scanf("%d", &candies[i]);
int xor = 0;
for (int i = 0; i < N; ++i)
    xor ^= candies[i];

  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?
13 years ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

no problem
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    You are right.  But I appreciate if you hide the answer in some way.
    • 13 years ago, # ^ |
        Vote: I like it +4 Vote: I do not like it
      I had the same problem in the past and I know what is the answer. I've lost several minutes to find out what's wrong when it happened in the past. I'm glad that this was on the local practice round. By the way (white text):

      I met the same problem with the word «link».

13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
That's interesting, would it still have error if adapted to pure C?
(white text)
...I think no, cause pure C has only 32 reserved words...
13 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

The answer is in the previous version.
13 years ago, # |
  Vote: I like it +3 Vote: I do not like it
It actually compiles just fine under MSVC++ (but fails under g++).
13 years ago, # |
  Vote: I like it +3 Vote: I do not like it
sometimes I had a similar problem on Timus online judge  because the name  next was reserved.