数据结构——模拟栈例题B3619

B3619 10 进制转 x 进制 - 洛谷

cpp 复制代码
#include <bits/stdc++.h>

using namespace std;
#define fs first
#define sc second
#define endl '\n'
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> PII;

char a[40];

void solve(){
    int n,x;
    cin>>n>>x;
    
    int h=0;
    
    while(n>=x)
    {
    	int t=n%x;
    	if(t>=10) a[h++]='A'+t-10;
    	else a[h++]=t+'0';
    	n/=x;
    }
    
    if(n>=10) a[h++]='A'+n-10;
    else a[h++]=n+'0';
    
    for(int i=h-1;i>=0;i--)cout<<a[i];
}

int main(){
	
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int t;
    t=1;

    while (t--)
    {
        solve();
    }
    
    return 0;
}
相关推荐
hetao173383722 分钟前
2025-12-12~14 hetao1733837的刷题笔记
数据结构·c++·笔记·算法
一直都在57228 分钟前
数据结构入门:时间复杂度与排序和查找
数据结构
sin_hielo3 小时前
leetcode 2110
数据结构·算法·leetcode
panzer_maus3 小时前
归并排序的简单介绍
java·数据结构·算法
摆烂且佛系3 小时前
B+树的“页分裂“机制
数据结构·b树
福尔摩斯张4 小时前
C++核心特性精讲:从C语言痛点出发,掌握现代C++编程精髓(超详细)
java·linux·c语言·数据结构·c++·驱动开发·算法
历程里程碑5 小时前
C++ 9 stack_queue:数据结构的核心奥秘
java·开发语言·数据结构·c++·windows·笔记·算法
仰泳的熊猫6 小时前
1108 Finding Average
数据结构·c++·算法·pat考试
晨晖26 小时前
顺序栈的入栈函数
数据结构
hweiyu007 小时前
数据结构:后缀自动机
数据结构