shen_yuhang @ 2025-01-11 15:23:48
#include <bits/stdc++.h>
using namespace std;
int n,r;
string sum=0;
int main()
{
cin>>n>>r;
while(n){
if(n/r<10){
sum+=n/r;
}else{
sum+=char(n/r-10+'A');
}
n/=r;
}
cout<<sum;
return 0;
}
by wky_wsy @ 2025-01-11 15:31:39
第 4 行的 string sum=0;
改成 string sum("");
第 10 行的 sum+=n/r
改成 sum+=to_string(n/r);
by wky_wsy @ 2025-01-11 15:35:22
@shen_yuhang
改完后只能解决 RE 的问题,我写的长这样:
#include <bits/stdc++.h>
using namespace std;
char z[10000000]="";
string m="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int r,n,l,i=0;
int main(){
scanf("%d%d",&n,&r);
l=n;
while(l){
z[i]=m[l%r];
l/=r;++i;
}
int L=strlen(z);
for(int i=L-1;i>-1;i--){
printf("%c",z[i]);
}
return 0;
}
by shen_yuhang @ 2025-01-11 15:44:33
#include <bits/stdc++.h>
using namespace std;
int n,r;
string sum;
int main()
{
cin>>n>>r;
while(n){
if(n/r<10){
sum+=n/r;
}else{
sum+=char(n/r-10+'A');
}
n/=r;
}
cout<<sum;
return 0;
}