首页
DreamJudge
院校信息
考研初试
机试真题
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
阿灿
2025年3月24日 21:26
0和1的个数 题解:整点不一样的
P1008
回复 0
|
赞 1
|
浏览 373
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; string k; k = bitset<32>(n).to_string(); int num=32; int count0=0,count1=0; for(int i=0;i<num;i++){ if(k[i]=='0'){ count0++; }else{ count1++; } } cout<<"count0="...
诗岸梦行舟
2025年3月11日 15:14
0和1的个数 题解:递归
P1008
回复 0
|
赞 2
|
浏览 424
#include<stdio.h> #include<stdlib.h> int n0,n1; int er(int a){ if(a==0) return 0; er(a/2); if((a%2)==0){ n0++; }else{ n1++; } return a%2; } int main(){ n0=n0=0; int n; scanf("%d",&n); er(n); printf("count0=%d count1=%d",32-n1,n1); }
西电机试专家
2025年3月10日 12:01
0和1的个数 题解:超简单思路
P1008
回复 0
|
赞 5
|
浏览 452
#include <bits/stdc++.h> using namespace std; //除基取余法 int main(){ int a; cin>>a; int count1=0; while(a>0) { int w=a%2; &...
zxjrheaven
2025年3月9日 13:40
0和1的个数 题解:暴力
P1008
回复 0
|
赞 2
|
浏览 514
#include <bits/stdc++.h> using namespace std; int num[32]={0}; int main() { int n; cin>>n; int count0=0; int count1=0; int j=0; &nbs...
jaygee_
2025年3月6日 18:56
0和1的个数 题解:
P1008
回复 0
|
赞 0
|
浏览 484
#include<bits/stdc++.h> using namespace std; int main() { int n, num0 = 0, num1 = 0; cin >> n; bitset<32> b(n); // 数字转32位二进制 string s = b.to_string(); for(int i = 0; i < (int)s.length(); i++) { if(s[i] == '0') num0 ++; else num1 ++; } cout <&l...
Candour
2024年4月20日 00:07
0和1的个数 (位运算)题解:
P1008
回复 0
|
赞 5
|
浏览 1.1k
#include<bits/stdc++.h> using namespace std; int n, cnt; int main() { cin >> n; while(n) { if(n & 1) cnt ++; n >>= 1; } printf("count0=%d count1=%d", 32 - cnt, cnt); return 0; }
小酒
2024年3月11日 15:54
0和1的个数 题解:
P1008
回复 3
|
赞 3
|
浏览 1.6k
1008解题思路 #include <bits/stdc++.h> using namespace std; int main() { int x,i=0; int count0=0,count1=0; int a[32]={0}; scanf("%d",&x); while(x>0) { &...
光明守护神
2024年3月17日 10:39
C++
P1008
回复 0
|
赞 3
|
浏览 991
#include<iostream> #include<string> using namespace std; int main() { int n; cin >> n; string s; while (n) { s += n % 2 + '0'; n /= 2; } int count0 = 0, count1 = 0; for (auto i = s.begin(); i != s.end(); i++) { if (*i == '1') { count1++;...
FCC
2024年3月15日 16:22
0和1的个数 题解:wihle循环实现除留余数法,将十进制转换成二进制
P1008
回复 0
|
赞 13
|
浏览 1.2k
int n; cin >> n; int count1 = 0; while (n != 0){ if (n % 2 == 1) count1++; n /= 2; } cout << "count0=" << 32 - count1 << " count1=" << count1; return 0;
orderrr
2024年3月15日 15:54
0和1的个数 题解:c解决 送分题
P1008
回复 0
|
赞 8
|
浏览 1.5k
#include <stdio.h> int main() { int n; int num[32] = {0}; while (scanf("%d", &n) != EOF) { int index = 0; while (n > 0) { num[index++] = n % 2; n = n / 2; } int count0 = 0, count1 = 0; ...
1
2
3
4
题目
0和1的个数
题解数量
34
发布题解
在线答疑
热门题解
1
0和1的个数 题解:wihle循环实现除留余数法,将十进制转换成二进制
2
1008二进制0和1的个数(不要忽略掉int的问题!!!!)
3
0和1的个数 题解:c解决 送分题
4
C++常规解法
5
0和1的个数 (位运算)题解:
6
0和1的个数 题解:超简单思路
7
0和1的个数 题解:
8
不断除以2,看最后一位的奇偶
9
0和1的个数 题解:代码相对来说简洁
10
C++