数据结构——模拟栈例题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;
}
相关推荐
Ameilide2 小时前
数据结构 树 二叉树
数据结构
WWW65263 小时前
代码随想录 打卡第四十七天
数据结构·算法·leetcode
cpp_25013 小时前
P10722 [GESP202406 六级] 二叉树
数据结构·c++·算法·题解·洛谷·树形结构·gesp六级
c238563 小时前
map和set
数据结构·c++
小欣加油5 小时前
leetcode239 滑动窗口最大值
数据结构·c++·算法·leetcode·哈希算法
炸薯条!5 小时前
二叉树的链式表示
数据结构·算法
CHHH_HHH5 小时前
【C++】二叉搜索树全面升级,深度剖析AVL树
开发语言·数据结构·c++·算法·stl
不会就选b5 小时前
数据结构之双向循环链表
数据结构·链表
悠仁さん6 小时前
数据结构OJ 简单算法题
数据结构
WBluuue6 小时前
数据结构与算法:树上启发式合并
数据结构·c++·算法·启发式算法