数据结构——模拟栈例题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;
}
相关推荐
CQ_YM7 小时前
数据结构之单向链表
c语言·数据结构·链表
im_AMBER9 小时前
算法笔记 18 二分查找
数据结构·笔记·学习·算法
C雨后彩虹9 小时前
机器人活动区域
java·数据结构·算法·华为·面试
苏小瀚10 小时前
[算法]---路径问题
数据结构·算法·leetcode
前端之虎陈随易11 小时前
MoonBit内置数据结构详解
数据结构·数据库·redis
CodeByV13 小时前
【算法题】双指针(二)
数据结构·算法
Jasmine_llq15 小时前
《P3811 【模板】模意义下的乘法逆元》
数据结构·算法·线性求逆元算法·递推求模逆元
虹科网络安全15 小时前
艾体宝干货 | Redis Java 开发系列#2 数据结构
java·数据结构·redis
sin_hielo16 小时前
leetcode 2211
数据结构·算法·leetcode