蓝桥题解:年号字串(进制转换)
小明用字母A 对应数字1,B 对应2,以此类推,用Z 对应26。对于27
以上的数字,小明用两位或更长位的字符串来对应,例如AA 对应27,AB 对
应28,AZ 对应52,LQ 对应329。
请问2019 对应的字符串是什么?
易知这是个10进制转26进制的问题,Z可以看成是 A @
答案:BYQ
#include<bits/stdc++.h>
using namespace std;
//题号:进制转换
string ntok(int n, int k)
{
string re;
while(n)
{
int t = n%k;
n/=k;
//A为1 ... Z为26
re = char('A'+t-1) + re;
}
return re;
}
int main()
{
cout<<ntok(2019,27);
return 0;
}