#include<stdio.h>
int main() {
int N,temp,count=; // 存储测试数据的二进制形式中1的个数
int bian[N]; // 输入十进制整数N 表示N行测试数据
scanf("%d",&N); // 循环读入
while(scanf("%d",&temp)!=EOF) {
bian[count]=; // 逐一计算二进制形式中1的个数 参考百度经验:http://jingyan.baidu.com/article/fc07f9892e245612ffe51909.html
while(temp!=) {
if(temp%!=) {
// 不能整除2的记录1
bian[count]++;
}
// 除以2更新下一个被除数 当被除数变为0时 说明结束
temp=temp/;
}
count++;
} // 输出N行测试数据结果
for(int i=; i<N; i++) {
printf("%d\n",bian[i]);
}
return ;
}
/*
pkuic_2709.c
计算概论(A)/基础编程练习2(8题)/8:1的个数
http://pkuic.openjudge.cn/base2/8
8:1的个数
查看 提交 统计 提问
总时间限制: 1000ms 内存限制: 65536kB
描述
给定一个十进制整数N,求其对应2进制数中1的个数
输入
第一个整数表示有N组测试数据,其后N行是对应的测试数据,每行为一个整数。
输出
N行,每行输出对应一个输入。
样例输入
4
2
100
1000
66
样例输出
1
3
6
2
*/

计算概论(A)/基础编程练习2(8题)/8:1的个数的更多相关文章

  1. 计算概论(A)/基础编程练习2(8题)/7:整数的个数

    #include<stdio.h> int main() { ] = {}; // 输入k个正整数 scanf("%d",&k); // 循环读入和进行算术 w ...

  2. 计算概论(A)/基础编程练习2(8题)/6:数组逆序重放

    #include<stdio.h> int main() { // 输入n个整数 ; scanf("%d", &n); // 循环读入元素 while(scan ...

  3. 计算概论(A)/基础编程练习2(8题)/5:点和正方形的关系

    #include<stdio.h> #include<math.h> int main() { // 输入坐标 float x, y; while(scanf("%f ...

  4. 计算概论(A)/基础编程练习1(8题)/2:苹果和虫子

    #include<stdio.h> #include<math.h> int main() { /* n个苹果 每x小时能吃掉一个苹果 经过y小时 */ float n, x, ...

  5. 计算概论(A)/基础编程练习1(8题)/1:大象喝水

    #include<stdio.h> int main() { ; // n < 100 scanf("%d", &n); // 循环遍历判断 再进行平方和 ...

  6. 计算概论(A)/基础编程练习2(8题)/4:骑车与走路

    #include<stdio.h> int main() { // 待处理的数据数量n ; scanf("%d", &n); float meters[n]; ...

  7. 计算概论(A)/基础编程练习2(8题)/3:计算三角形面积

    #include<stdio.h> #include<math.h> int main() { // 声明三角形的三个顶点坐标和面积 float x1, y1, x2, y2, ...

  8. 计算概论(A)/基础编程练习2(8题)/2:计算书费

    #include<stdio.h> int main() { // 声明与初始化 ; // k组测试数据的总费用 double s[k]; // 单价表 double price[]= { ...

  9. 计算概论(A)/基础编程练习2(8题)/1:求平均年龄

    #include<stdio.h> int main() { // 声明与初始化 , s=, age=; // 输入学生人数 scanf("%d", &n); ...

随机推荐

  1. webstorm2018版安装-破解

    安装完成后到下面网址下载破解补丁 网址:http://idea.lanyus.com/ 修改路径 修改同目录下的 WebStorm.exe.vmoptions 和WebStorm64.exe.vmop ...

  2. golang 编译或链接 c语言动态、静态库的方法, golang 与 c语言 相互调用

    1.golang链接c静态库的方法可以见这个示例: https://github.com/atercattus/go-static-link-example https://github.com/sh ...

  3. JAVA基础——时间Date类型转换

    在java中有六大时间类,分别是: 1.java.util包下的Date类, 2.java.sql包下的Date类, 3.java.text包下的DateFormat类,(抽象类) 4.java.te ...

  4. 常用笔记:MySQL

    [MySQL] mysql -h192.168.0.201 -P3306 -uroot -p123 -D数据库名 #命令行连接数据库 SET PASSWORD = PASSWORD('123456') ...

  5. Nginx Log日志统计分析常用命令

    IP相关统计 统计IP访问量(独立ip访问数量) awk '{print $1}' access.log | sort -n | uniq | wc -l 查看某一时间段的IP访问量(4-5点) gr ...

  6. 236A

    #include <stdio.h> #include <string.h> int main() { char str[150]; int arr[35]; memset(s ...

  7. 自动出借-python+selenium

    自动出借 import time from selenium import webdriver # import os #B username = " # 请替换成你的用户名 passwor ...

  8. python beautiful soup库的超详细用法

    原文地址https://blog.csdn.net/love666666shen/article/details/77512353 参考文章https://cuiqingcai.com/1319.ht ...

  9. cocos2d-x 暂停/恢复 与场景相关(SceneGraph类型)的监听器

    开发过程中,我们经常会遇到这样的情况:想要让一个Layer中所有的Node对象的事件都停止响应. 在响应用户事件后,又要恢复该Layer的所有事件响应. 如: 用户想要显示一个模式对话框,显示对话框后 ...

  10. 实验:记录一则删除GI的过程

    环境: RHEL 6.5 + Oracle GI 11.2.0.4 (2 nodes) 参考MOS文档 How to Deconfigure/Reconfigure(Rebuild OCR) or D ...