数据结构——模拟栈例题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;
}
相关推荐
mifengxing12 小时前
LeetCode 189 轮转数组|3种解法拆解,从暴力到O(1)原地最优解
数据结构·算法·leetcode
MIngYaaa52012 小时前
2026暑期牛客多校3 2026-7-24
数据结构·算法·000
2501_9378609412 小时前
Java 集合底层深度剖析:Map 与 Set、二叉搜索树、哈希表全解
java·数据结构·散列表
Hommy8813 小时前
【剪映小助手】字符串列表转对象接口(Str List To Obds)
数据结构·list·剪映小助手·视频剪辑自动化·剪映api·开源剪映小助手
noipp14 小时前
推荐题目:洛谷 P3726 [AHOI2017/HNOI2017] 抛硬币
c语言·数据结构·c++·算法·编程·洛谷·luogu
wabs66614 小时前
关于链表【力扣19.删除链表的倒数第N个节点的思考】
数据结构·leetcode·链表
Rabitebla14 小时前
C++ STL 之 set 详解:从底层红黑树到实际应用
开发语言·数据结构·c++·算法·leetcode
520拼好饭被践踏14 小时前
JAVA+Agent学习day26
java·开发语言·数据结构·学习·agent
郝学胜-神的一滴14 小时前
力扣 692:巧用小顶堆高效求解前K个高频单词
java·数据结构·python·程序人生·算法·leetcode·职场和发展
额,不知道写啥。15 小时前
题解:P16710 愿望
数据结构·算法