数据结构——模拟栈例题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;
}
相关推荐
0+1115 小时前
算法 --链表
数据结构·算法·leetcode·链表
夜之眷属8 小时前
PriorityQueue:for-each 遍历和 poll 取出,顺序一样吗?
java·服务器·数据结构·后端·算法
思维新观察8 小时前
三星 Galaxy Tab S12 系列:大屏 AI 平板,兼顾轻薄与生产力
数据结构·人工智能·电脑
杜 硕9 小时前
快速排序详解01
数据结构·算法·排序算法
信奥卷王10 小时前
[GESP202606 六级] 满二叉树
数据结构·算法
念越11 小时前
题库、练习与错题本代码阅读
开发语言·数据结构
垆边人似月.12 小时前
华为题:盛最多水的容器
数据结构·算法
HPtiger12 小时前
数据结构——插入排序
数据结构·排序算法
All for pursuit.12 小时前
【动态规划-11】279.完全平方数
数据结构·c++·算法·leetcode·动态规划
Logic10113 小时前
C语言/数据结构位运算题解:异或XOR找出套碗游戏中的“幸运碗“——只出现一次的数字
c语言·数据结构·算法·数组·位运算·时间复杂度·空间复杂度