数据结构——模拟栈例题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;
}
相关推荐
疯狂打码的少年1 小时前
【数据结构】树的基本概念与二叉树定义
java·数据结构·笔记·算法
小龙报3 小时前
【优选算法】1.搜索插入位置 2.x的平方根
java·c语言·数据结构·c++·python·算法·蓝桥杯
rimydu1974art3 小时前
# OpenCheck 废标风控系统技术实现
数据结构
rannn_1114 小时前
【力扣hot100】链表专题|21、2、19、24、92、25
java·数据结构·算法·leetcode·链表·开发
Gust of wind4 小时前
数据结构基础:线性表及其存储实现
数据结构
Rabitebla5 小时前
C++11 新特性详解(一):列表初始化、initializer_list 与右值引用
java·开发语言·数据结构·c++·算法·leetcode·list
zephyr055 小时前
链表实现O(n log n)时间复杂度的排序——归并排序详解
java·数据结构·算法
XWalnut6 小时前
LeetCode刷题 day37
java·数据结构·算法·leetcode
爱跳舞的烤冷面7 小时前
自学嵌入式第19天(数据结构篇——栈)
数据结构
星轨初途8 小时前
LeetCode 热题 100——day11 滑动窗口最大值
数据结构·c++·算法·leetcode·职场和发展