文章

25

粉丝

9

获赞

2

访问

12.1k

头像
十进制和二进制 题解:
P1176 清华大学上机题
发布于2024年8月26日 13:55
阅读数 312

评测值:173先过

如果只过一半,应该是大整数没满足

可以试试10个9 

在线二进制按位逆序运算工具-Bejson.com

//都是bigInt的转换
//十进制转二进制,二进制转十进制 
//有多次输入 
//都是根据int的形式下的原理进行模拟
//类似与高精度
//十进制转二进制,求back%2,other/2获得下一次
//二进制转十进制,所有ou位均*2,每轮+ou.front 

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

bool isZero(vector<int> de){
	for(auto i: de) {
		if(i != 0) return false;
	}
	return true;
}

vector<int> tran(string str){
	vector<int> de(1000);
	vector<int> bi;
	vector<int> ou(1000,0);
	int num;
	int len = str.size();
	for(int i = 0; i<=len-1; i++){
		if(str[i]>='0'&&str[i]<='9'){
			num = str[i] - '0';
			de.push_back(num);
		}
	}
	//十进制转二进制
	while(!isZero(de)){
		num = de.back()%2;
		for(int i = 0; i<=de.size()-1; i++){
			de[i+1] += de[i]%2*10;
			de[i] /= 2;
		}
		bi.push_back(num);
	}

	//输出不能是int类型的,位数不够
	//字符串二进制转字符串十进制,类高精度运算
	//每一位都*2
	//ou初...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发