数据结构——模拟栈例题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;
}
相关推荐
流年如夢35 分钟前
二叉树详解
c语言·数据结构·算法
博界IT精灵44 分钟前
二叉排序树和平衡二叉树(哈喜老师)
数据结构·考研
木子墨5161 小时前
工程算法实战 | 从LRU到手写本地缓存:LinkedHashMap → 双向链表+哈希表 → Caffeine 原理
java·数据结构·算法·链表·缓存
流年如夢2 小时前
二叉树(LeetCode)
数据结构·算法·leetcode·职场和发展
玉树临风ives2 小时前
atcoder ABC 457 题解
数据结构·c++·算法
驭渊的小故事2 小时前
Java数据结构集合框架(栈(Stack)的详细解析)2000字详细解析
数据结构
宵时待雨3 小时前
回溯算法专题1:递归
数据结构·c++·笔记·算法·leetcode·深度优先
如竟没有火炬4 小时前
去除重复字母——贪心+单调栈
开发语言·数据结构·python·算法·leetcode·深度优先
风味蘑菇干4 小时前
斗地主案例
java·数据结构·算法
Languorous.4 小时前
C++数据结构高阶|B+树深度解析:从底层原理到数据库应用,面试高频考点全覆盖
数据结构·b树·面试