Блог пользователя fixme

Автор fixme, 13 лет назад, По-английски

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];

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

13 лет назад, # |
Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

no problem
  • 13 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    You are right.  But I appreciate if you hide the answer in some way.
    • 13 лет назад, # ^ |
        Проголосовать: нравится +4 Проголосовать: не нравится
      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 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
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 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

The answer is in the previous version.
13 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится
It actually compiles just fine under MSVC++ (but fails under g++).
13 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
Some c++ but not C keywords:
and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq
The C++ Programming Language by Bjarne Stroustrup
13 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится
sometimes I had a similar problem on Timus online judge  because the name  next was reserved.