数据结构——模拟栈例题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;
}
相关推荐
苏小瀚4 小时前
[数据结构] ArrayList(顺序表)与LinkedList(链表)
数据结构
Kevinhbr8 小时前
CSP-J/S IS COMING
数据结构·c++·算法
Armyyyyy丶8 小时前
Redis底层实现原理之五大基础结构
数据结构·redis·缓存
金古圣人8 小时前
hot100 滑动窗口
数据结构·c++·算法·leetcode·哈希算法
JJJJ_iii8 小时前
【左程云算法03】对数器&算法和数据结构大致分类
数据结构·算法·分类
天选之女wow12 小时前
【代码随想录算法训练营——Day4】链表——24.两两交换链表中的节点、19.删除链表的倒数第N个节点、面试题02.07.链表相交、142.环形链表II
数据结构·算法·leetcode·链表
胡萝卜3.012 小时前
数据结构初阶:树的相关性质总结
数据结构·二叉树·性质·二叉树的性质
KarrySmile12 小时前
Day12--HOT100--23. 合并 K 个升序链表,146. LRU 缓存,94. 二叉树的中序遍历
数据结构·链表·二叉树·递归·hot100·lru·灵茶山艾府
今后12318 小时前
【数据结构】带哨兵位双向循环链表
数据结构·链表
Lee嘉图18 小时前
数据结构——队列(Java)
数据结构