2 条题解
-
1
Infinity_ LV 8 @ 2024-08-26 16:53:39
#include<iostream> using namespace std; bool b[30]; int main(){ ios::sync_with_stdio(false); int n, i = 1; cin >> n; while(n != 0){ b[i] = (n & 1); n = (n >> 1); i++; } while(--i)cout << b[i]; return 0; } -
1@ 2024-07-17 15:23:32
#include <iostream>
#include <string>std::string decimalToBinary(int n) {
std::string binary = "";
if (n == 0) {
return "0";
}
while (n > 0) {
binary = (n % 2 == 0 ? "0" : "1") + binary;
n = n / 2;
}
return binary;
}int main() {
int number;
std::cin>>number; // 示例数字
std::string binary = decimalToBinary(number);
std::cout<< binary << std::endl;
return 0;
}
- 1
信息
- ID
- 1554
- 难度
- 5
- 分类
- (无)
- 标签
- 递交数
- 288
- 已通过
- 106
- 通过率
- 37%
- 被复制
- 4
- 上传者