题解 | #二进制数#

二进制数

https://www.nowcoder.com/practice/103dd589fed14457a673c613d8de3841

//土尔逊Torson 编写于2023/5/03
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <stdlib.h>

using namespace std;

int main() {
	unsigned int n;
	while (scanf("%d",&n)!=EOF) {
		vector<int> binary;
		while (n != 0) {
			binary.push_back(n % 2);
			n /= 2;
		}
		for (int i = binary.size() - 1; i >= 0; --i) {//逆序输出
			printf("%d", binary[i]);
		}
		printf("\n");
	}
	system("pause");
	return EXIT_SUCCESS;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务