20

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

Sx0528 @ 2024-08-31 11:52:05

#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
    long long n,x;
    cin>>n>>x;
    if(n==0)
    {
        cout<<n<<endl;
        return 0;
    }
    int y,s;
    while(y!=0)
    {
        y=n/x;
        s=n%x;
        char d;
        if(s<10) d=s+48;
        else d=s+55;
        a+=d;
        n=y;
    }
    for(int i=a.size()-1;i>=0;i--)
    {
        cout<<a[i];
    }
    return 0;
}

by dongzirui0817 @ 2024-08-31 11:55:59

@Sx0528 你样例都没过耶……


by dongzirui0817 @ 2024-08-31 11:58:43

@Sx0528 好像这代码都不输出


by dongzirui0817 @ 2024-08-31 12:02:15

@Sx0528 y 初始化为 n


by Sx0528 @ 2024-08-31 12:04:19

已关,求回关


|