算法之旅,直奔<bitset>之五 count
2013-12-24 16:00
405 查看
count(vs2010)
这是我学习总结<bitset>的第五篇。有时候我们需要计算位集合中1或0的个数,count来帮助你。
作用
count的作用计算位集合中1或0的个数。
实验
代码
test.cpp
#include <iostream> // std::cout #include <string> // std::string #include <bitset> // std::bitset int main () { std::bitset<8> foo (std::string("10110011")); std::cout << foo << " has "; std::cout << foo.count() << " ones and "; std::cout << (foo.size()-foo.count()) << " zeros.\n"; system("pause"); return 0; }
相关文章推荐
- 算法之旅,直奔<algorithm>之十 count_if
- 算法之旅,直奔<bitset>之六 none
- 算法之旅,直奔<bitset>之七 to_ulong
- 算法之旅,直奔<algorithm>之九 count
- 算法之旅,直奔<bitset>之一 to_string
- 算法之旅,直奔<bitset>之八 flip
- 算法之旅,直奔<algorithm>之十 count_if
- 算法之旅,直奔<bitset>之二 size
- 算法之旅,直奔<bitset>之三 test
- 算法之旅,直奔<bitset>之四 set
- 算法之旅,直奔<algorithm>之十七 find_first_of
- 算法之旅,直奔<algorithm>之二十一 max
- 算法之旅,直奔<algorithm>之二十二 sort
- 算法之旅,直奔<algorithm>之二 adjacent_find
- 算法之旅,直奔<algorithm>之十三 fill
- 算法之旅,直奔<algorithm>之一 all_of
- 算法之旅,直奔<algorithm>之十四 fill_n
- 算法之旅,直奔<algorithm>之三 any_of
- 算法之旅,直奔<algorithm>之八 copy_n
- 算法之旅,直奔<algorithm>之十八 for_each