数据结构——模拟栈例题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;
}
相关推荐
风落青芜2 小时前
C++入门:类和对象(二)
开发语言·数据结构·c++·算法
风落青芜3 小时前
C++入门:类和对象(三)
开发语言·数据结构·c++·算法
杜 硕5 小时前
从零开始的C++生活——第十五讲
开发语言·数据结构·c++·生活
小白的高手之路5 小时前
【LeetCode 热题 100】560. 和为 K 的子数组|前缀和、哈希表(Python)
数据结构·笔记·python·算法·leetcode·力扣·散列表
蓝色汪洋7 小时前
qsort使用指南
数据结构·算法
Code_Solitude8 小时前
c语言:期末复习5(二维数组)
c语言·数据结构·算法
charliejohn8 小时前
计算机考研 408 数据结构 散列表 平均查找长度 ASL
数据结构·散列表
charliejohn8 小时前
计算机考研 408 数据结构 图的概念及例题
数据结构
Shaoshing11 小时前
LeetCode100 32.最长有效括号
java·数据结构·leetcode
Lazyafei11 小时前
560. 和为 K 的子数组
数据结构·算法