首页
DreamJudge
院校信息
考研初试
考研复试
保研专区
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
myhy001
2019年12月8日 18:54
int型4字节一个字节存放8个0或者1
P1008
回复 0
|
赞 3
|
浏览 10.0k
#include<stdio.h> int main() { int n,i=0,j=0; scanf("%d",&n); while(n>=1) { if(n%2==1) j++; n=n/2;...
南山不落梅
2019年12月8日 22:01
大家来评评理,我这个能算出结果但是提交答案错误
P1008
回复 2
|
赞 0
|
浏览 9.1k
#include<stdio.h> int main(){ int a,one=0; scanf("%d",&a); for(;a!=0;a=a/2,one+=1); printf("count0=%d count1=%d",32-one,one); return 0; }
codesuc
2020年3月5日 17:15
虽然这里通过了,但编译器没出结果,搞求不懂
P1008
回复 2
|
赞 0
|
浏览 10.6k
#include<stdio.h> int main(){ int i=0,j=0,a,b; scanf("%d",&a); while(a!=0){ b=a%2; a=a/2; if(b==1) i+=1; } j=32-i; printf("count0=%d count1=%d",j,i); return 0; }
wugenqiang
2020年3月30日 17:59
P1008 - 0 和 1 的个数 - C
P1008
回复 0
|
赞 1
|
浏览 12.5k
/*给定一个int型整数,输出这个整数的二进制的0和1的个数。 输入样例:15 输出样例:count0=28 count1=4*/ #include <stdio.h> int main(){ int n; scanf("%d",&n);//输入int整数 int cnt = 0;//定义1的个数 while(n > 0){ if(n % 2){ cnt++;//记录1的个数 } n /= 2; } printf("count0=%d count1=%d\n",32-cnt,cnt); ...
猛士骁将
2020年3月12日 17:57
p1008 - 0和1的个数(C语言)
P1008
回复 0
|
赞 1
|
浏览 11.3k
本程序解法:将所给的十进制数转成二进制数(方法见 https://jingyan.baidu.com/article/f0e83a255ca20422e59101f5.html),然后统计1的个数 注意:int占4个字节,32位 #include <stdio.h> int main() { int n = 0, left = 0, count1 = 0;//left记录当前余数 scanf("%d", &n); &nb...
谦虚使人进步
2020年1月16日 09:30
这是我第一遍想到的结果,还没想有没有更好的,写完全部有时间再做一遍
P1008
回复 0
|
赞 0
|
浏览 9.1k
#include <iostream> using namespace std; int main(void){ int input=0,N1=0; cin >> input; while(input!=0){ if(input%2==1){ N1++...
A1120161820
2020年3月18日 16:17
0和1的个数(c++)
P1008
回复 0
|
赞 2
|
浏览 11.1k
#include<iostream> using namespace std; int main() { int num; cin >> num; int count = 0; //int有32位,需要保证0和1的总数为32,所以只需要记录1的个数即可 while (num > 0) { if (num%2 == 1)//该二进制位为1 count++; num /= 2; } cout << "count0=" << 32-count << " count1=...
1
2
3
4
题目
0和1的个数
题解数量
37
发布题解
在线答疑
热门题解
1
0和1的个数 题解:wihle循环实现除留余数法,将十进制转换成二进制
2
1008二进制0和1的个数(不要忽略掉int的问题!!!!)
3
0和1的个数 题解:c解决 送分题
4
0和1的个数 题解:超简单思路
5
C++常规解法
6
0和1的个数 (位运算)题解:
7
0和1的个数 题解:暴力
8
0和1的个数 题解:整点不一样的
9
0和1的个数 题解:
10
不断除以2,看最后一位的奇偶