bal*_*aji 1 c c++
如何计算8位字符串中出现次数1.例如10110001.位字符串取自用户.像10110001那样应该使用什么类型的数组来存储c中的这个位串?
Pra*_*rav 5
简短而简单.使用std::bitset(C++)
std::bitset
#include <iostream> #include <bitset> int main() { std::bitset<8> mybitstring; std::cin >> mybitstring; std::cout << mybitstring.count(); // returns the number of set bits }
Ideone的在线测试
归档时间:
14 年,6 月 前
查看次数:
2062 次
最近记录:
12 年,6 月 前