1 / 2
Nov 2012

Hi guys,

I get Wrong Answer in problem 9500 BITCNTR (Bit counts) although i passed all the provided test cases in the problem description, i don't know whats wrong!!
Can any body helps me before i go mad ? :_(
here is the code

#include <iostream>
using namespace std;
main(){
  int testcases = 0, x = 0, y = 0, sum = 0;
  while(cin >> testcases){
     for(int i=0; i<testcases; i++){
         cin >> y;
         while(1){
            x = y % 2;
            if(x == 1) sum++;
            y = y / 2;
           if(y == 0) break;
         }
         cout << sum << "\n";
         sum = 0;
     }
  }
}

This code passes this test case:
5
2
3
1
0
11

Thanks in advance.

  • created

    Nov '12
  • last reply

    Nov '12
  • 1

    reply

  • 153

    views

  • 2

    users

There are 512 possible test cases. Have you verified them all?

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 19 12d

Want to read more? Browse other topics in C and C++ or view latest topics.