Birthday Cake Candles

  • + 17 comments
    while(std::cin >> n)
            max < n ? c = !!(max = n) : c += max == n;
    

    can be translated as:

    while(std::cin >> n){ // for each candle n check:
        if(max < n) { // does n set a new record in height?
            max = n; // if that's so, then n is the new max height
            c = 1; // and the counter c must be set to 1 again. "!!" is a cheap trick to convert any value different from 0 into 1
        }
        else { // otherwise check if the new candle is as tall as max
            if (max == n)
                c++; // in that case, add 1 to counter (otherwise add 0)
        }
    }