数据结构——模拟栈例题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;
}
相关推荐
Yeats_Liao12 小时前
MindSpore开发之路(八):数据处理之Dataset(上)——构建高效的数据流水线
数据结构·人工智能·python·机器学习·华为
客梦13 小时前
数据结构-线性表
数据结构·笔记
鹿角片ljp13 小时前
力扣226.翻转二叉树-递归
数据结构·算法·leetcode
WBluuue14 小时前
数据结构和算法:Morris遍历
数据结构·c++·算法
客梦14 小时前
数据结构-红黑树
数据结构·笔记
Sheep Shaun15 小时前
STL:string和vector
开发语言·数据结构·c++·算法·leetcode
winfield82115 小时前
滑动时间窗口,找一段区间中的最大值
数据结构·算法
k***921616 小时前
list 迭代器:C++ 容器封装的 “行为统一” 艺术
java·开发语言·数据结构·c++·算法·list
x70x8016 小时前
C++中auto的使用
开发语言·数据结构·c++·算法·深度优先
sin_hielo17 小时前
leetcode 2054(排序 + 单调栈,通用做法是 DP)
数据结构·算法·leetcode