数据结构——模拟栈例题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;
}
相关推荐
琢磨先生David17 小时前
Day1:基础入门·两数之和(LeetCode 1)
数据结构·算法·leetcode
qq_4542450318 小时前
基于组件与行为的树状节点系统
数据结构·c#
超级大福宝18 小时前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode
岛雨QA19 小时前
常用十种算法「Java数据结构与算法学习笔记13」
数据结构·算法
weiabc19 小时前
printf(“%lf“, ys) 和 cout << ys 输出的浮点数格式存在细微差异
数据结构·c++·算法
wefg119 小时前
【算法】单调栈和单调队列
数据结构·算法
岛雨QA19 小时前
图「Java数据结构与算法学习笔记12」
数据结构·算法
czxyvX19 小时前
020-C++之unordered容器
数据结构·c++
岛雨QA19 小时前
多路查找树「Java数据结构与算法学习笔记11」
数据结构·算法
AKA__Zas19 小时前
初识基本排序
java·数据结构·学习方法·排序