Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор alternatego, 13 лет назад, По-английски
In round #85 div 2, question A using this function was very helpful
cout << strcasecmp(a,b) << endl;

Here are some more useful functions found in gnu extensions, but not in standard library
__typeof() 
#define REP(i,n) for (__typeof(n) i = 0; i < n; ++i)

__builtin_popcount(n) - counts the number of set bits in n. Example, for 10 it prints 2.

Are there anymore  gnu extensions which you find useful? And what's codeforces policy on that?
Теги gnu
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

13 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
Does anybody know, how __builtin_popcount extension implemented?
  • 13 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    You can read tutorial written by bmerry. There is a short point on its implementation.
    • 13 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      Yes, that's good. Thank you. It seems that using __bultin_popcount instead of straight implementation is a good idea.
13 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I can't believe this damn REP macro is built-in.Or is it just an example of typeof usage? Anyway, you don't need __ prefix to use it.
  • 13 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    It's an example of __typeof. 
    REP(i,10) 
    REP(i, v.size()) - Iterating over all elements of vector
    REP(i, s.size()) - Iterating over all characters of a string
    You can also write a foreach macro using __typeof() and then iterate over sets, maps etc
    • 13 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      Yes, I know its usage. Actually, there is range-based for in c++11 standard, not sure if it is supported by the codeforces g++ compiler, but it's very likely.