例:1010(二进制)一共4位,我们分解为4步。
一;0(第零位数)*2+1(第一位数)=1(运行数)
二;1(运行数)*2+0(第二位数)=2(运行数)
三;2(运行数)*2+1(第三位数)=5(运行数)
四;5(运行数)*2+0(第四位数)=10(运行数)
例:212(三进制)一共3位,我们分解3步
一:0(第零位数)*3+2(第一位数)=2(运行数)
二;2(运行数)*3+1(第二位数)=7(运行数)
三;7(运行数)*3+2(第三位数)=23(运行数)
方法一:
#includeusing namespace std; int fan(string a,int b){ int res=0; int c=a.size(); for(int i=0;i >a>>b; int c=fan(a,b); cout< 方法二:
#includeusing namespace std; int fan(string a,int b){ int res=0; for(auto &c:a) res=res*b+c-'0'; return res; } int main(){ string a; int b; cin>>a>>b; int c=fan(a,b); cout<



