数据结构——模拟栈例题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;
}
相关推荐
皓月斯语19 分钟前
【C++基础】三目运算符
开发语言·数据结构·c++
剑锋所指,所向披靡!2 小时前
数据结构之拓扑排序
数据结构
夜不会漫长4 小时前
数据结构:链表
数据结构·链表
剑锋所指,所向披靡!5 小时前
数据结构之关键路径
数据结构·算法
笨笨饿5 小时前
101_详解USB协议
java·jvm·数据结构
J-Tony116 小时前
【Redis】数据结构&&持久化
数据结构·数据库·redis
来一碗刘肉面6 小时前
队列的链式实现
数据结构·c++·算法·链表
奶人五毛拉人一块7 小时前
二分算法以及习题讲解
数据结构·算法·二分
兰令水7 小时前
hot100【acm版】【2026.7.19打卡-java版本】
java·数据结构·算法·leetcode·面试
LJHclasstore_luo8 小时前
【C++题解】112354.平行时空
数据结构·c++·算法