TLE#1,2,4,5 20pts
查看原帖
TLE#1,2,4,5 20pts
615166
zhouzihang3楼主2023/10/13 21:10

rt

使用栈,悬关

#include<bits/stdc++.h> 
#define returnO_o return 0
#define loser long long
using namespace std;
int a,b,x,y,idx;
string n;
string bk="0123456789ABCDEFG";
stack<char>dq;
int main(){
	cin>>a>>n>>b;
	y=n.size();
	idx=pow(a,y-1);
	for(int i=0;i<y;i++,idx/=a) x+=bk.find(n[i])*idx;
	dq.push(bk[x%b]);
	while(x!=1){
		x/=b;
		dq.push(bk[x%b]);
	}
	while(!dq.empty()){
		cout<<dq.top();
		dq.pop();
	}
	returnO_o;
}
2023/10/13 21:10
加载中...