We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Other Concepts
- C++ Variadics
- Discussions
C++ Variadics
C++ Variadics
Sort by
recency
|
122 Discussions
|
Please Login in order to post a comment
this is a long code but it works. :-)
stack stk; void reversed_binary(){} template void reversed_binary(int b, Digits... digits){ stk.push(b); reversed_binary(digits...);
}
template int reversed_binary_value(){ reversed_binary(digits...); int sum = 0; if(stk.size() > 0){ int pos = stk.size() - 1; if(pos == 0) return 1 * stk.top(); long long prd = 1; for(int count = pos; count > 0; --count) prd *= 2; for(; pos > 0; --pos){ int b = stk.top(); prd /= 2; sum += b * prd; stk.pop(); } } return sum; }
I have read what this exercise asks over and over, even asked chat gpt(4) to help me interpret it, somebody should really rewrite it, its frustrating.