解题思路:
注意事项:
参考代码:
#include <bits/stdc++.h> using namespace std; int bbb[20]; int main() { int a,b; string str; cin>>a>>str>>b; int n=str.size(); int str1[n]; for(int i=0;i<n;i++) { if(str[i]=='A'||str[i]=='a') { str1[i]=10; } if(str[i]=='B'||str[i]=='b') { str1[i]=11; } if(str[i]=='C'||str[i]=='c') { str1[i]=12; } if(str[i]=='D'||str[i]=='d') { str1[i]=13; } if(str[i]=='E'||str[i]=='e') { str1[i]=14; } if(str[i]=='F'||str[i]=='f') { str1[i]=15; } if(str[i]=='0') { str1[i]=0; } if(str[i]=='1') { str1[i]=1; } if(str[i]=='2') { str1[i]=2; } if(str[i]=='3') { str1[i]=3; } if(str[i]=='4') { str1[i]=4; } if(str[i]=='5') { str1[i]=5; } if(str[i]=='6') { str1[i]=6; } if(str[i]=='7') { str1[i]=7; } if(str[i]=='8') { str1[i]=8; } if(str[i]=='9') { str1[i]=9; } } int sum=0; int j=0; for(int i=n-1;i>=0;i--) { int y=pow(a,j); int x=str1[i]; sum+=x*y; j++; } //sum//十进制数字 for(int i=1; ;i++) { if(sum<b) { bbb[i]=sum; bbb[i+1]=900; break; } bbb[i]=sum%b; sum/=b; } int sum1=0; for(int i=1;i<=20;i++) { if(bbb[i]==900) { break; } sum1++; } int jj=0; for(int i=sum1;i>=1;i--) { if(bbb[i]==0) { cout<<"0"; } if(bbb[i]==1) { cout<<"1"; } if(bbb[i]==2) { cout<<"2"; } if(bbb[i]==3) { cout<<"3"; } if(bbb[i]==4) { cout<<"4"; } if(bbb[i]==5) { cout<<"5"; }if(bbb[i]==6) { cout<<"6"; }if(bbb[i]==7) { cout<<"7"; } if(bbb[i]==8) { cout<<"8"; } if(bbb[i]==9) { cout<<"9"; } if(bbb[i]==10) { cout<<"A"; } if(bbb[i]==11) { cout<<"B"; } if(bbb[i]==12) { cout<<"C"; } if(bbb[i]==13) { cout<<"D"; } if(bbb[i]==14) { cout<<"E"; } if(bbb[i]==15) { cout<<"F"; } } return 0; }
0.0分
1 人评分