csl851231 @ 2024-11-16 18:25:09
第一个不对怎么办?大佬求解
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,r;
char a[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char b[]="";
cin>>n>>r;
int m=0;
while (n>0){
int i=n%r;
b[m]=a[i];
m++;
n/=r;
}
for(int i=m-1;i>=0;i--){
cout<<b[i];
}
}
by 0oOo0 @ 2024-11-16 18:30:45
@csl851231 把a,b数组定义为全局,而且把b数组加上范围(10^6+5),去掉后面的赋值
#include <bits/stdc++.h>
using namespace std;
char a[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char b[1000005];
int main()
{
int n,r;
cin>>n>>r;
int m=0;
while (n>0){
int i=n%r;
b[m]=a[i];
m++;
n/=r;
}
for(int i=m-1;i>=0;i--){
cout<<b[i];
}
}
by csl851231 @ 2024-11-16 19:03:40
@0oOo0谢谢,已关
by EVA0 @ 2024-12-04 13:33:58
对吗?
#include <iostream>
using namespace std;
int a[20];
char ans[20];
char atoans[50] = {'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;
int mx = 0;
for(int i=0; i<n; i++){
a[0]++;
for(int j=0; j<20; j++){
if(a[j] >= r){
if(j + 1 > mx) mx = j+1;
a[j+1]++;
a[j] = 0;
}
}
}
for(int i=0; i<=mx; i++){
ans[i] = atoans[a[i]];
}
for(int i=mx; i>=0; i--){
cout<<ans[i];
}
cout<<endl;
return 0;
}