数据结构——模拟栈例题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;
}
相关推荐
Tairitsu_H40 分钟前
[LC优选算法#17] 链表 | 合并 K 个升序链表 | K个⼀组翻转链表
数据结构·算法·链表
zwenqiyu3 小时前
非线性字符串数据结构串讲
数据结构·c++·学习·算法
东华万里4 小时前
第32篇 数据结构入门 单链表的增删查改实现
数据结构·链表
OOJO6 小时前
哈希表实现
数据结构·哈希算法·散列表
剑挑星河月9 小时前
234. 回文链表
java·数据结构·算法·leetcode·链表
六bring个六9 小时前
链表学习(常规链表)
数据结构·学习·链表
tachibana21 天前
hot100 回文链表(234)
java·网络·数据结构·leetcode·链表
aaaameliaaa1 天前
进制练习题【找出只出现一次的数字、交换两个变量(不创建临时变量)、统计二进制中1的个数、打印整数二进制的奇数位和偶数位、求两个数二进制中不同位的个数】
c语言·数据结构·笔记·算法
-dzk-1 天前
【系统架构设计师】案例分析篇
开发语言·数据结构·python·算法·架构·系统架构·架构设计
东华万里1 天前
第30篇 代码习惯 初学C与数据结构有感
c语言·数据结构·大学生专区