坠机

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

_safdsfdeaf_ @ 2024-10-03 10:49:13

#include<bits/stdc++.h> 
#include<queue>
using namespace std;
int main()
{
    queue<char>a;
    int n,r,n1,w=0,num=0;
    cin>>n>>r;
    n1=n;
    while(n1!=0){
        n1/=10;
        w++;
    }
    n1=n;
    for(int i=1;i<=w;i++){
        if(pow(n1%10,i)>9)
            a.push((char)(pow(n1%10,i)+55));
        else
            a.push((char)(pow(n1%10,i)+48));
    }
    while(!a.empty()){
        cout<<a.front();
        a.pop();
    }
    return 0;
}

不知错在哪(悬关)(崩溃一百天)


by zhs_TLE @ 2024-10-03 11:12:01

15~20行好像是其他进制转十进制吧


by zhs_TLE @ 2024-10-03 11:12:52

直接模拟短除就行了呀


by zhs_TLE @ 2024-10-03 11:19:19

我不会用queue 所以这个代码输出是反的,你自己改一下吧

#include<bits/stdc++.h> 
#include<queue>
using namespace std;
int main()
{
    queue<char>a;
    int n,r,y;
    cin>>n>>r;
    while(n!=0){
        int g=n%r;
        if(g>9) a.push((char)(g+55));
        else a.push((char)(g+48));
        n/=r;
    }
    while(!a.empty()){
        cout<<a.front();
        a.pop();
    }
    return 0;
}

by zhs_TLE @ 2024-10-03 11:19:37

@safdsfdeaf


by Iamhim @ 2024-10-20 14:33:57

你好菜啊


by MLSY_OIer_ZXL @ 2024-10-26 19:51:47

都是绿名,我也来占个光


|