#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. nodejs, vue, webpack 项目实践

    vue 及 webpack,均不需要与nodejs一期使用,他们都可以单独使用到任何语言的框架中. http://jiongks.name/blog/just-vue/ https://cn.vuej ...

  2. https://github.com/Lushenggang/show-pdf在线浏览pdf文件在线浏览pdf文件

    在线浏览pdf文件 https://github.com/Lushenggang/show-pdf https://github.com/Lushenggang/show-pdf

  3. 算法笔记-PHP实现队列的操作

    [队列]先进者先出,这就是典型的“队列”.         最基本的两个操作:入队enqueue(),放一个数据到队列尾部:出队dequeue(),从队列头部取一个元素.队列可以用数组或者链表实现,用 ...

  4. 三维bfs(HUD1253胜利大逃亡)

    #include <stdio.h>#include <string.h>int map[51][51][51];int v[51][51][51];int a,b,c,t11 ...

  5. python安装pandas模块

    直接安装时报错了 localhost:~ ligaijiang$ pip3 install pandas Collecting pandas Downloading https://files.pyt ...

  6. bootstrap评分插件 Bootstrap Star Rating Examples

    http://www.jq22.com/demo/bootstrap-star-rating-master201708041812/

  7. JS--变量及深浅拷贝

    JS变量分为基本类型和引用类型 基本类型数据包括Number, String, Boolean, Null, Undefined五种类型: 引用数据类型包括Array, Date, RegExp, F ...

  8. web.config或App.config中AttachDBFilenamex相对路径问题

    <add name="employeeManagerConnectionString" connectionString="Data Source=.\SQLExp ...

  9. webpack的使用二

    1.安装 Webpack可以使用npm安装,新建一个空的练习文件夹(此处命名为webpack sample project),在终端中转到该文件夹后执行下述指令就可以完成安装 //全局安装 npm i ...

  10. mint-ui Picker的使用

    <template> <div v-bind:style="{minHeight:clientHeight + 'px'}" id="recive-mi ...