计算概论(A)/基础编程练习2(8题)/8:1的个数
#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的个数的更多相关文章
- 计算概论(A)/基础编程练习2(8题)/7:整数的个数
#include<stdio.h> int main() { ] = {}; // 输入k个正整数 scanf("%d",&k); // 循环读入和进行算术 w ...
- 计算概论(A)/基础编程练习2(8题)/6:数组逆序重放
#include<stdio.h> int main() { // 输入n个整数 ; scanf("%d", &n); // 循环读入元素 while(scan ...
- 计算概论(A)/基础编程练习2(8题)/5:点和正方形的关系
#include<stdio.h> #include<math.h> int main() { // 输入坐标 float x, y; while(scanf("%f ...
- 计算概论(A)/基础编程练习1(8题)/2:苹果和虫子
#include<stdio.h> #include<math.h> int main() { /* n个苹果 每x小时能吃掉一个苹果 经过y小时 */ float n, x, ...
- 计算概论(A)/基础编程练习1(8题)/1:大象喝水
#include<stdio.h> int main() { ; // n < 100 scanf("%d", &n); // 循环遍历判断 再进行平方和 ...
- 计算概论(A)/基础编程练习2(8题)/4:骑车与走路
#include<stdio.h> int main() { // 待处理的数据数量n ; scanf("%d", &n); float meters[n]; ...
- 计算概论(A)/基础编程练习2(8题)/3:计算三角形面积
#include<stdio.h> #include<math.h> int main() { // 声明三角形的三个顶点坐标和面积 float x1, y1, x2, y2, ...
- 计算概论(A)/基础编程练习2(8题)/2:计算书费
#include<stdio.h> int main() { // 声明与初始化 ; // k组测试数据的总费用 double s[k]; // 单价表 double price[]= { ...
- 计算概论(A)/基础编程练习2(8题)/1:求平均年龄
#include<stdio.h> int main() { // 声明与初始化 , s=, age=; // 输入学生人数 scanf("%d", &n); ...
随机推荐
- WeChat-结构
- [py]类的专有方法
陆陆续续总结一些用到的类的特殊方法 看源码总会看到一些奇奇怪怪的写法: 掺杂着设计模式 https://coding.net/u/RuoYun/p/Python-design-pattern/git/ ...
- case关联表查询
select a.员工编号,b.`姓名`,b.`地址`,case when a.收入 is null then '没钱' when a.收入 < 2000 then '低收入'when a.收入 ...
- 58A
#include <stdio.h> #include <string.h> int main() { char hel[6]="hello"; char ...
- Python爬虫常用模块安装
安装:pip3 install requestspip3 install seleniumpip3 install bs4pip3 install pyquerypip3 install pymysq ...
- PHP DDOS的UDP攻击,TCP攻击,和CC攻击的核心代码
网络安全向,请勿用作非法用途 CC攻击模块: <?phpecho “状态 : 正常运行中…..<br>”;echo “================================ ...
- js中变量提升(一个是变量,一个是函数表达式都会存在变量提升,函数声明不存在)
一.变量提升 在ES6之前,JavaScript没有块级作用域(一对花括号{}即为一个块级作用域),只有全局作用域和函数作用域.变量提升即将变量声明提升到它所在作用域的最开始的部分.上个简历的例子如: ...
- Solaris 10主机名和IP地址步骤
1.修改主机名: hostname newname vi /etc/hosts vi /etc/hostname.e1000g0 vi /etc/nodename init 6 #重启 --confi ...
- VirtualBox下扩容vdi文件
VirtualBox下扩容vdi文件 版本:VirtualBox 5.0.14 之前VirtualBox创建的虚拟机的vdi文件过小,无法满足新的实验需求,扩容vdi文件的方法如下: 比如我这里将RH ...
- 常用脚本lnmp
3)安装lnmp脚本只供参考需修改相应参数 #!/bin/bash#Function: Install LNMP#Author: wang#Date: 20170809 nginx_install() ...