1 条题解
-
0
C++ :
#include<bits/stdc++.h> using namespace std; //10进制转2进制 int n; string r = "";//存放转换结果 int c0 = 0,c1 = 0; int main(){ cin>>n; if(n == 0){ cout<<1<<" "<<0<<endl; return 0; } //当n!=0循环 while(n != 0){ //cout<<n%2;//取余 //将n%2的结果转换为字符+到r前面 //r = char(n%2+'0') + r; if(n % 2 == 0) c0++; else c1++; n=n/2;//除2 } //特判输入为0的情况 cout<<c0<<" "<<c1<<endl; return 0; }
- 1
信息
- ID
- 2121
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者