csuoj-1732-XueXX and Binary
2016-05-27 09:54
363 查看
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 casesT(T<=100). The descriptions of the test cases follow: The first line of each test case contains one integera
(0<a<=1,000,000,000), standing for the number in decimal.
Output
For each test case, output a single line containing the result.Sample Input
3 1 91 735
Sample Output
1 5 8
二进制数1的个数
#include <cstdio> #include <iostream> using namespace std; int n; int main(){ int T; scanf("%d", &T); while (T--){ scanf("%d", &n); int ans = 0; while (n){ if (n & 1) ++ans; n >>= 1; } printf("%d\n", ans); } return 0; }
相关文章推荐
- MQTT Mosquitto broker with SSL/TLS transport security
- Errors running builder 'DeploymentBuilder' on project '工程名'
- csuoj-1731-XueXX and P-P String
- getRequestDispatcher()与sendRedirect()的区别
- 关于UIFont的初始化
- android项目编译报错:error occurred during the build
- ScrollView与UIPageController
- iOS 8UIAlertcontroller如何实现 message左对齐 ,title居中显示
- Minigui-3.0.12 开发记录
- primary key与unique的区别
- iOS中的UIStepper数值加减器用法指南
- iOS开发之高级视图—— UICollectionViewController
- 【Arduino官方教程第一辑】示例程序 5-4 Switch和Case条件语句
- No package identifier when getting value for resource num 0x00000000 【安卓资源找不到】
- NGUI中sprite出现透明边框(黑线)
- NGUI适配问题
- 【CodeForces】675A - Infinite Sequence
- 使用UUID生成验证码
- UITableViewCell添加自定义view,在cell选中高亮时,view消失,取消高亮时,view又出现
- int8 uint8 区别