解题思路:

注意事项:

参考代码:

#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.0分

1 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论