文章

24

粉丝

0

获赞

254

访问

8.3k

头像
二进制数 题解:
P1380 北京邮电大学机试题
发布于2025年3月6日 23:37
阅读数 229

使用string库函数

#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
	int n;
	string s;
	while(cin >> n) {
		int cnt = 0;
		if(n == 0) {
			cout << '0' << endl;
			continue;
		}
		while(n > 0) {
			int num = n % 2;
			a[cnt ++] = num;
			n /= 2;
		}
		
		for(int i = cnt - 1; i >= 0; i --) {
			s += to_string(a[i]);
			cout << s;
			s.clear();
		}
		cout << endl;
	}
	 
 	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发