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

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

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
  • Проголосовать: не нравится

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

no problem
15 лет назад, скрыть # |
 
Проголосовать: нравится 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...
15 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

The answer is in the previous version.
15 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится
It actually compiles just fine under MSVC++ (but fails under g++).
15 лет назад, скрыть # |
 
Проголосовать: нравится 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
15 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится
sometimes I had a similar problem on Timus online judge  because the name  next was reserved.