十進位制轉十六進位制(藍橋杯之前每日一題)

前方是否可導?發表於2020-10-09
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long ll;
char getchar(ll x){
    if(x>=0&&x<=9)return x+'0';
    else return 'A'+(x-10);
}
string getans(ll x){
    string ans="";
    if(x==0)return "0";
    while(x){
        ans+=getchar(x%16);
        x=x/16;
    }
    return ans;
    }
int main()
{
    ll a;
    cin>>a;
    string s=getans(a);
    reverse(s.begin(),s.end());
    cout <<s<< endl;

    return 0;
}

相關文章