国防科大校赛决赛-final(镜像赛) Problem B: XueXX and Binary
2016-05-15 17:43
423 查看
Description
XueXX is a clever boy. And he always likes numbers in binary(二进制). What an interesting hobby!
Now XueXX has some number in decimal(十进制), he wants to know how many “1”s in a number if the number is written in binary.
Input
The first line of input contains the number of test cases T (T<=100). The descriptions of the test cases follow: The first line of each test case contains one integer a (0
XueXX is a clever boy. And he always likes numbers in binary(二进制). What an interesting hobby!
Now XueXX has some number in decimal(十进制), he wants to know how many “1”s in a number if the number is written in binary.
Input
The first line of input contains the number of test cases T (T<=100). The descriptions of the test cases follow: The first line of each test case contains one integer a (0
#include<iostream> #include<string> #include<algorithm> using namespace std; int main() { int t; cin>>t; while(t--) { int n,ans=0; cin>>n; while(n) { n&=n-1; ans++; } cout<<ans<<endl; } return 0; }
相关文章推荐
- Burp Suite使用详解
- 使用 Equinox 开发 OSGi 应用程序
- poj 1458 Common Subsequence
- 【LeetCode】95. Unique Binary Search Trees II
- Java源码学习 -- java.lang.StringBuilder,java.lang.StringBuffer,java.lang.AbstractStringBuilder
- php中include()和require()的区别
- LeetCode 60. Permutation Sequence
- 在Android Studio中进行单元测试和UI
- 【GIT】使用GIT GUI 连接到conding码库教程
- OC NSNumber NSValue
- Android中的UI
- 算法导论学习--快速排序--Quicksort
- [leetcode]347. Top K Frequent Elements
- MQTT协议 - Mosquitto安装测试
- J Arithmetic Sequence (华农第四届) 求数组中最长等差数列
- Ex2010-06 Get version number, build number
- android UI——2D绘图中应该注意的那些坑
- requirejs搭建前端框架
- Problem J: Arithmetic Sequence
- Arduino 与 土壤湿度传感器 测量土壤湿度自动浇水提醒