数据结构——模拟栈例题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;
}
相关推荐
老菜鸡mou37 分钟前
[OD E 100] 生成哈夫曼树
数据结构·c++
和光同尘@1 小时前
56. 合并区间 (LeetCode 热题 100)
c语言·开发语言·数据结构·c++·算法·leetcode·职场和发展
CS创新实验室2 小时前
计算机考研之数据结构:大 O 记号
数据结构·考研
wen__xvn3 小时前
每日一题洛谷P1914 小书童——凯撒密码c++
数据结构·c++·算法
BUG 劝退师4 小时前
八大经典排序算法
数据结构·算法·排序算法
小小小白的编程日记5 小时前
List的基本功能(1)
数据结构·c++·算法·stl·list
_Itachi__5 小时前
LeetCode 热题 100 283. 移动零
数据结构·算法·leetcode
柃歌5 小时前
【UCB CS 61B SP24】Lecture 5 - Lists 3: DLLists and Arrays学习笔记
java·数据结构·笔记·学习·算法
商bol455 小时前
复习dddddddd
数据结构·c++·算法
干炒 牛河9 小时前
数据结构:哈希表(unordered_map)
数据结构·算法·散列表