数据结构——模拟栈例题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;
}
相关推荐
量子炒饭大师2 分钟前
Cyber骇客的脑机双链回流码 ——【初阶数据结构与算法】线性表之双向链表
数据结构·c++·链表
2401_841495644 分钟前
【LeetCode刷题】缺失的第一个正数
数据结构·python·算法·leetcode·数组·哈希·缺失最小正整数
C++业余爱好者6 分钟前
Java 中的数据结构详解及应用场景
java·数据结构·python
拼好饭和她皆失22 分钟前
二分答案算法详解:从理论到实践解决最优化问题
数据结构·算法·二分·二分答案
月明长歌27 分钟前
【码道初阶】Leetcode234进阶版回文链表:牛客一道链表Hard,链表的回文结构——如何用 O(1) 空间“折叠”链表?
数据结构·链表
CoderYanger33 分钟前
C.滑动窗口-求子数组个数-越长越合法——2962. 统计最大元素出现至少 K 次的子数组
java·数据结构·算法·leetcode·职场和发展
小满、38 分钟前
Redis:高级数据结构与进阶特性(Bitmaps、HyperLogLog、GEO、Pub/Sub、Stream、Lua、Module)
java·数据结构·数据库·redis·redis 高级特性
月明长歌1 小时前
【码道初阶】Leetcode面试题02.04:分割链表[中等难度]
java·数据结构·算法·leetcode·链表
如竟没有火炬1 小时前
快乐数——哈希表
数据结构·python·算法·leetcode·散列表
蒙奇D索大1 小时前
【数据结构】考研408 | B树探秘:从查找操作到树高性能分析
数据结构·笔记·b树·考研·改行学it