2 solutions

  • 0
    @ 2023-2-11 15:33:47
    #include<bits/stdc++.h>
    using namespace std;
    int i[1000000];
    int a1,b1,q;
    
    void solve(int a,int b){
    	q=0;
    	while(a>b){
    		i[q]=a%b;
    		q++;
    		a-=a%b;
    		a/=b;
    	}
    	i[q]=a;
    }
    
    int main()
    {
    	cin>>a1>>b1;
    	solve(a1,b1);
    	for(int c=q;c>=0;c--){
    		if(i[c]>=10){
    			char b='A'+i[c]-10;
    			cout<<b;
    		}else{
    			cout<<i[c];
    		}
    	}
    }
    
    • 0
      @ 2023-2-9 22:33:44
      求佬指点怎么改进
      #include<stdio.h>
      int sum[36]={0};
      void fun(int n,int m);
      int main()
      {
      	int n,m;
      	scanf("%d%d",&n,&m);
      	fun(n,m);
      	
      	return 0;
      }
      
      
      
      void fun(int n,int m)
      {
      	char s[37]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
      	int t=1;
      	while(n>m)
      	{
      		sum[t]=n%m;
      //		printf("%d\n",n%m);
      		t++;
      		n=n/m;
      	//
      		if(m>n)
      		{
      			sum[t]=n;
      		}
      	
      	}
      //	printf("%d\n",t);
      	while(t>0)
      	{
      	//	printf("%d\n",sum[t]);
      		printf("%c",s[sum[t]]);
      	t--;
      	 } 
      }
      
      • 1

      Information

      ID
      6691
      Time
      1000ms
      Memory
      128MiB
      Difficulty
      4
      Tags
      (None)
      # Submissions
      27
      Accepted
      16
      Uploaded By