Dev SKill Solution DCP-22: Number Base


Problem Link
Dev SKill Solution DCP-22: Number Base
#include<bits/stdc++.h>
using namespace std;
void number(long long n,int b)
{
    vector<int>v;
    char a;

    while(n>0)
    {
        v.push_back(n%b);
        n=n/b;
    }
    int l=v.size();
    for(int i=l-1;i>=0;i--)
    {
        if(v[i]<10)
            cout<<v[i];
        else
        {
            a=v[i]+55;
            cout<<a;
        }
    }
    cout<<endl;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long n;
        int b;
        char c;
        cin>>n>>c>>b;
        if(n==0)
            cout<<"0"<<endl;
        else
            number(n,b);
    }
    return 0;
}

No comments

Theme images by enjoynz. Powered by Blogger.