Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A non-empty array A of N elements contains octal representation of a non-negative integer K, i.e. each element of A belongs to the interval [0; 7]
- Write a function:
- int bitcount_in_big_octal(const vector<int> &A);
- that returns the number of bits set to 1 in the binary representation of K. The function should return -1 if the number of bits set to 1 exceeds 10,000,000.
- Assume that the array can be very large.
- Assume that:
- N is an integer within the range [1..100,000];
- My answer:
- //this is java
- public int bitcount_in_big_octal ( int[] A ) {
- int count[] ={0,1,1,2,1,2,2,3};
- int sum =0;
- for(int i=0;i<A.length;i++){
- sum+=count[A[i]];
- }
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement