80分求解!!

B3849 [GESP样题 三级] 进制转换

aibianchengdezhang @ 2024-12-17 12:00:55


#include<bits/stdc++.h>
using namespace std;
int n,r,a[1000001],p = 1; 
int main() {
    scanf("%d\n%d",&n,&r);
    while(true){
        a[p] = n % r; 
        if(n / r) n /= r;
        else break;
        p++;        
    }
    for(int i = sizeof(a)/sizeof(a[0]) - 1;i > 0 ;i--){
        if(a[i] >= 0 && a[i] <= 9) printf("%d",a[i]);
        else if(a[i] >= 10 && a[i] <= 35) printf("%c",char(a[i] + 55));
    }
    return 0;
}

by niuniudundun @ 2024-12-17 12:47:51

@aibianchengdezhang

改 AC 了:

#include<bits/stdc++.h>
using namespace std;
int n,r,a[1000001],p = 1; 
int main() {
    scanf("%d\n%d",&n,&r);
    while(n){//错误1
        a[p] = n % r; 
        n/=r;//错误2
        p++;        
    }
    for(int i = p - 1;i > 0 ;i--){//错误3
        if(a[i] >= 0 && a[i] <= 9) printf("%d",a[i]);
        else if(a[i] >= 10 && a[i] <= 35) printf("%c",char(a[i] + 55));
    }
    return 0;
}

求关。


by aibianchengdezhang @ 2024-12-17 13:30:18

@[niuniudundun](luogu://user/100感谢,已关注


|