hby110 @ 2025-01-12 19:12:24
能不能帮忙Debug一下!!谢谢了
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
string s="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
int t,r,n,m=0,i;
int a[1000];
memset(a,0,sizeof(a));
cin>>t>>r;
m=0;
if(t<r){
cout<<t;
}else{
while(t>r){
if(t/r<r){
n=t/r;
}
m++;
a[m]=t%r;
t/=r;
}
cout<<n;
for(i=m;i>=1;i--){
cout<<s[a[i]];
}
}
return 0;
}
by 4041nofoundGeoge @ 2025-01-12 19:18:18
@hby110能不能写简单一点?
#include <bits/stdc++.h>
using namespace std;
char a[2222]={'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 main()
{
int n,r;
cin>>n>>r;
string s;
while(n!=0){
s+=a[n%r];
n=(n-n%r)/r;
}
reverse(s.begin(),s.end());
cout<<s;
return 0;
}