Chinaunix首页 | 论坛 | 博客
  • 博客访问: 77923
  • 博文数量: 14
  • 博客积分: 1972
  • 博客等级: 上尉
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-25 13:04
文章分类

全部博文(14)

文章存档

2012年(3)

2011年(8)

2010年(3)

分类: C/C++

2012-04-15 04:01:21


点击(此处)折叠或打开

  1. #include <iostream>
  2. #include <string>
  3. #include <bitset>

  4. using namespace std;

  5. int f(int value)
  6. {
  7.     bitset<8*sizeof(int)> bitValue(value);
  8.     string strValue=bitValue.to_string();

  9.     int iLength=strValue.length();
  10.     int iCount=0;
  11.     for (int i=0;i!=iLength;++i)
  12.     {
  13.         if (strValue.at(i)=='1')
  14.         {
  15.             ++iCount;
  16.         }
  17.     }

  18.     return iCount;
  19. }

  20.     

  21. int main()
  22. {
  23.     int i=f(13);
  24.     cout<<i;

  25.     system("pause");
  26.     return 0;
  27. }

阅读(1070) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~