So basically want a program that would print the column name of google docs for example:-
Also, the input number can be a really large value eg the range can be up to long.
function printColName(columnNumber){ ... return colName }
printColName(4) => D
printColName(27) => AA
printColName(55) => BC
This is a very common problem and has appeared in multiple contests before. Check this problem.
Here is my code for reference-
Code
#include<bits/stdc++.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
void fun(ll n)
{
if(n>0)
{
n--;
fun(n/26);
cout<<char(n%26+65);
}
}
void solve(){
ll n;
cin>>n;
fun(n);
}
int32_t main()
{
fio;
ll t=1;
for(ll dd=1;dd<=t;dd++){
solve();
}
}
3 Likes