50分,求救!大佬帮忙改改吧!必关!
查看原帖
50分,求救!大佬帮忙改改吧!必关!
1652416
shenyuanzaiqi楼主2025/7/2 11:22

#include <bits/stdc++.h>
using namespace std;
long long a1,c1,f,h;
string b1,s1,s2;
long long xs(long long k,string x){
	long long t=0,s=0,a[2000]={},h=0;
	h=x.size()-1;
	for(int j=0;j<=h;j++){
		if(x[j]>='A'){	
			a[j]=int(x[j]-55);
		}
		else{
			a[j]=int(x[j]-48);
		}
	}
	t=1;
	s=0;
	for(int j=h;j>=0;j--){
		s+=t*a[j];
		t*=k;
	}
	return s;
}
string sx(long long n,long long b){
	string s;
	long long x;
	char c;
	if(b>=11){
		if(n==0){	
			return "0";
		}
		while(n!=0){ 
			x=n%b;
			if(x<10){
				c=x+'0';	
			} 
			else{
				c=x-10+'0'+49;
			}
			s=c+s;
			n=n/b;
		}
	}
	if(b<=10){
		if(n==0) {
			return "0";
		}
		while(n!=0) {
			x=n%b;
			c=x+'0';
			s=c+s;
			n=n/b;
		}
	}
	return s;
}
int main(){
	a1=8;c1=16;f=0;
	s2="";
	cin>>b1;
	h=b1.size()-1;
	for(int i=h;i>=0;i-=4){
		if(i<=2){
			s1=b1;
		}
		else{
			s1="";
			s1+=b1[i-3];
			s1+=b1[i-2];
			s1+=b1[i-1];
			s1+=b1[i];
			b1.erase(b1.end()-4,b1.end());
		}	
		s2=sx(xs(a1,s1),c1)+s2;	
	}
	cout<<s2;
}
2025/7/2 11:22
加载中...