数据结构——模拟栈例题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;
}
相关推荐
sin_hielo2 小时前
leetcode 1390
数据结构·算法·leetcode
一只专注api接口开发的技术猿4 小时前
从原理到实现:淘宝商品详情 API 的数据结构与调用机制剖析
大数据·数据结构·数据库·架构
H_BB9 小时前
前缀和算法详解
数据结构·算法
聆风吟º9 小时前
【数据结构手札】时间复杂度详解:概念 | 大O渐进表示法 | 习题
数据结构·算法·时间复杂度·大o渐进表示法
好奇龙猫10 小时前
【大学院-筆記試験練習:线性代数和数据结构(1)】
数据结构·数学
橘颂TA14 小时前
【剑斩OFFER】算法的暴力美学——两数之和
数据结构·算法·leetcode·力扣·结构与算法
tobias.b14 小时前
408真题-2009-7-数据结构-无向连通图性质
数据结构·算法·408考研·408真题·真题解析
阿猿收手吧!14 小时前
【C++】JSON核心数据结构解析及JSONCPP使用
数据结构·c++·json
tobias.b15 小时前
408真题解析-2009-9-数据结构-小根堆-排序
数据结构·408考研·408真题·真题解析
D_FW15 小时前
数据结构第二章:线性表
数据结构·算法